file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
GTWP.fst
GTWP.wp
val wp : a: Type -> Type
let wp (a:Type) = pure_wp a
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 17, "start_col": 0, "start_line": 17 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp" ]
[]
false
false
false
true
true
let wp (a: Type) =
pure_wp a
false
Lib.ByteSequence.fst
Lib.ByteSequence.nat_from_intseq_le_public_to_secret
val nat_from_intseq_le_public_to_secret: #t:inttype{unsigned t} -> len:size_pos{len * bits t < pow2 32} -> b:lseq (uint_t t PUB) len -> Lemma (nat_from_intseq_le b == nat_from_intseq_le (map secret b))
val nat_from_intseq_le_public_to_secret: #t:inttype{unsigned t} -> len:size_pos{len * bits t < pow2 32} -> b:lseq (uint_t t PUB) len -> Lemma (nat_from_intseq_le b == nat_from_intseq_le (map secret b))
let rec nat_from_intseq_le_public_to_secret #t len b = if len = 1 then begin nat_from_intseq_le_lemma0 b; nat_from_intseq_le_lemma0 (map secret b) end else begin let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_le_public_to_secret #t (len - 1) b1; //assert (nat_from_intseq_le b1 == nat_from_intseq_le (map secret b1)); nat_from_intseq_le_slice_lemma b 1; nat_from_intseq_le_lemma0 (slice b 0 1); //assert (nat_from_intseq_le b == nat_from_intseq_le (slice b 0 1) + pow2 (bits t) * nat_from_intseq_le (slice b 1 len)); nat_from_intseq_le_slice_lemma b_secret 1; nat_from_intseq_le_lemma0 (slice b_secret 0 1); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); () end
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 836, "start_col": 0, "start_line": 820 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i) let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; } let uints_to_bytes_le_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_le_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) (nat_to_bytes_le (len * numbytes t) n) val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1)) let index_nat_to_intseq_to_bytes_be #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc (==) { Seq.index (nat_to_bytes_be #l m (v s.[len - 1 - i / m])) (m - (i % m) - 1); == { index_nat_to_intseq_be #U8 #l m (v s.[len - 1 - i / m]) (i % m) } uint (v s.[len - 1 - i / m] / pow2 (8 * (i % m)) % pow2 8); == { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); == { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); == { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); } val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i) let uints_to_bytes_be_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in calc (==) { Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i; == { index_uints_to_bytes_be_aux #t #l len n i } Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_be #t #l len n (len * numbytes t - 1 - i)} Seq.index (nat_to_bytes_be (len * numbytes t) n) i; } let uints_to_bytes_be_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_be_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) (nat_to_bytes_be (len * numbytes t) n) #push-options "--max_fuel 1" let rec nat_from_intseq_le_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_le_inj (Seq.slice b1 1 (length b1)) (Seq.slice b2 1 (length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end let rec nat_from_intseq_be_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_be_inj (Seq.slice b1 0 (length b1 - 1)) (Seq.slice b2 0 (length b2 - 1)); Seq.lemma_split b1 (length b1 - 1); Seq.lemma_split b2 (length b2 - 1) end let lemma_nat_to_from_bytes_be_preserves_value #l b len x = () let lemma_nat_to_from_bytes_le_preserves_value #l b len x = () let lemma_uint_to_bytes_le_preserves_value #t #l x = () let lemma_uint_to_bytes_be_preserves_value #t #l x = () let lemma_nat_from_to_intseq_le_preserves_value #t #l len b = nat_from_intseq_le_inj (nat_to_intseq_le len (nat_from_intseq_le b)) b let lemma_nat_from_to_intseq_be_preserves_value #t #l len b = nat_from_intseq_be_inj (nat_to_intseq_be len (nat_from_intseq_be b)) b let lemma_nat_from_to_bytes_le_preserves_value #l b len = lemma_nat_from_to_intseq_le_preserves_value len b let lemma_nat_from_to_bytes_be_preserves_value #l b len = lemma_nat_from_to_intseq_be_preserves_value len b let lemma_reveal_uint_to_bytes_le #t #l b = () let lemma_reveal_uint_to_bytes_be #t #l b = () let lemma_uint_to_from_bytes_le_preserves_value #t #l i = lemma_reveal_uint_to_bytes_le #t #l (uint_to_bytes_le #t #l i); assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v (uint_from_bytes_le #t #l (uint_to_bytes_le #t #l i))); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i) let lemma_uint_to_from_bytes_be_preserves_value #t #l i = lemma_reveal_uint_to_bytes_be #t #l (uint_to_bytes_be #t #l i); lemma_uint_to_bytes_be_preserves_value #t #l i let lemma_uint_from_to_bytes_le_preserves_value #t #l s = let i = uint_from_bytes_le #t #l s in let s' = uint_to_bytes_le #t #l i in lemma_nat_from_to_bytes_le_preserves_value #l s' (length s'); assert(nat_to_bytes_le #l (length s') (nat_from_bytes_le s') == s'); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i); assert(s' == nat_to_bytes_le #l (length s') (uint_v i)); assert(s' == nat_to_bytes_le #l (length s') (uint_v (uint_from_bytes_le #t #l s))); lemma_reveal_uint_to_bytes_le #t #l s; assert(s' == nat_to_bytes_le #l (length s') (nat_from_bytes_le s)); lemma_nat_from_to_bytes_le_preserves_value #l s (length s) let lemma_uint_from_to_bytes_be_preserves_value #t #l s = let i = uint_from_bytes_be #t #l s in let s' = uint_to_bytes_be #t #l i in lemma_nat_from_to_bytes_be_preserves_value #l s' (length s'); assert(nat_to_bytes_be #l (length s') (nat_from_bytes_be s') == s'); lemma_uint_to_bytes_be_preserves_value #t #l i; assert(nat_from_bytes_be (uint_to_bytes_be #t #l i) == uint_v i); assert(s' == nat_to_bytes_be #l (length s') (uint_v i)); assert(s' == nat_to_bytes_be #l (length s') (uint_v (uint_from_bytes_be #t #l s))); lemma_reveal_uint_to_bytes_be #t #l s; assert(s' == nat_to_bytes_be #l (length s') (nat_from_bytes_be s)); lemma_nat_from_to_bytes_be_preserves_value #l s (length s) let rec nat_from_intseq_be_public_to_secret #t len b = if len = 1 then begin nat_from_intseq_be_lemma0 b; nat_from_intseq_be_lemma0 (map secret b) end else begin let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_be_public_to_secret #t (len - 1) b1; //assert (nat_from_intseq_be b1 == nat_from_intseq_be (map secret b1)); nat_from_intseq_be_slice_lemma b 1; nat_from_intseq_be_lemma0 (slice b 0 1); //assert (nat_from_intseq_be b == nat_from_intseq_be b1 + pow2 ((len - 1) * bits t) * v b.[0]); nat_from_intseq_be_slice_lemma b_secret 1; nat_from_intseq_be_lemma0 (slice b_secret 0 1); //assert (nat_from_intseq_be b_secret == nat_from_intseq_be b1_secret + pow2 ((len - 1) * bits t) * v b_secret.[0]); //assert (v b.[0] == v b_secret.[0]); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); () end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_pos{len * Lib.IntTypes.bits t < Prims.pow2 32} -> b: Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.PUB) len -> FStar.Pervasives.Lemma (ensures Lib.ByteSequence.nat_from_intseq_le b == Lib.ByteSequence.nat_from_intseq_le (Lib.Sequence.map Lib.IntTypes.secret b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned", "Lib.IntTypes.size_pos", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Prims.pow2", "Lib.Sequence.lseq", "Lib.IntTypes.uint_t", "Lib.IntTypes.PUB", "Prims.op_Equality", "Prims.int", "Lib.ByteSequence.nat_from_intseq_le_lemma0", "Lib.IntTypes.SEC", "Lib.Sequence.map", "Lib.IntTypes.secret", "Prims.unit", "Prims.bool", "Lib.Sequence.eq_intro", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Lib.Sequence.slice", "Lib.ByteSequence.nat_from_intseq_le_slice_lemma", "Lib.ByteSequence.nat_from_intseq_le_public_to_secret", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.l_Forall", "Prims.nat", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Prims.l_imp" ]
[ "recursion" ]
false
false
true
false
false
let rec nat_from_intseq_le_public_to_secret #t len b =
if len = 1 then (nat_from_intseq_le_lemma0 b; nat_from_intseq_le_lemma0 (map secret b)) else let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_le_public_to_secret #t (len - 1) b1; nat_from_intseq_le_slice_lemma b 1; nat_from_intseq_le_lemma0 (slice b 0 1); nat_from_intseq_le_slice_lemma b_secret 1; nat_from_intseq_le_lemma0 (slice b_secret 0 1); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.mul_def
val mul_def (a b: poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i: nat). {:pattern p.[ i ]} i < len ==> p.[ i ] == mul_element a b i))
val mul_def (a b: poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i: nat). {:pattern p.[ i ]} i < len ==> p.[ i ] == mul_element a b i))
let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 182, "start_col": 0, "start_line": 173 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Prims.Pure Vale.Math.Poly2_s.poly
Prims.Pure
[]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2_s.of_fun", "Prims.nat", "Vale.Math.Poly2.Galois.mul_element", "Prims.bool", "Prims.int", "Prims.op_Addition", "Vale.Math.Poly2.Galois.poly_length", "Prims.l_True", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.l_imp", "Prims.op_LessThan", "Prims.eq2", "Vale.Math.Poly2_s.op_String_Access" ]
[]
false
false
false
false
false
let mul_def (a b: poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i: nat). {:pattern p.[ i ]} i < len ==> p.[ i ] == mul_element a b i)) =
let len = poly_length a + poly_length b in of_fun len (fun (i: nat) -> mul_element a b i)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_shift_right
val lemma_shift_right (f:G.field) (e:G.felem f) (n:I.shiftval f.G.t) : Lemma (requires True) (ensures to_poly (I.shift_right e n) == shift (to_poly e) (-(I.uint_v n))) [SMTPat (to_poly (I.shift_right e n))]
val lemma_shift_right (f:G.field) (e:G.felem f) (n:I.shiftval f.G.t) : Lemma (requires True) (ensures to_poly (I.shift_right e n) == shift (to_poly e) (-(I.uint_v n))) [SMTPat (to_poly (I.shift_right e n))]
let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n)))
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 146, "start_col": 0, "start_line": 139 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t))
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.GaloisField.field -> e: Spec.GaloisField.felem f -> n: Lib.IntTypes.shiftval (GF?.t f) -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.to_poly (Lib.IntTypes.shift_right e n) == Vale.Math.Poly2_s.shift (Vale.Math.Poly2.Galois.to_poly e) (- Lib.IntTypes.uint_v n)) [SMTPat (Vale.Math.Poly2.Galois.to_poly (Lib.IntTypes.shift_right e n))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Lib.IntTypes.shiftval", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.op_disEquality", "Lib.IntTypes.U1", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2.Galois.to_poly", "Lib.IntTypes.shift_right", "Vale.Math.Poly2_s.shift", "Prims.op_Minus", "Lib.IntTypes.uint_v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "FStar.UInt.size", "FStar.UInt.shift_right", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_reverse_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let lemma_shift_right f e n =
let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (- (I.uint_v n)))
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.d
val d (a: poly) : (b: D.poly{poly == D.poly /\ coerce D.poly a == b})
val d (a: poly) : (b: D.poly{poly == D.poly /\ coerce D.poly a == b})
let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 261, "start_col": 0, "start_line": 259 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2.Defs_s.poly { Vale.Math.Poly2_s.poly == Vale.Math.Poly2.Defs_s.poly /\ Vale.Math.Poly2_s.coerce Vale.Math.Poly2.Defs_s.poly a == b }
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2_s.to_poly", "Prims.unit", "Vale.Math.Poly2_s.reveal_defs", "Vale.Math.Poly2.Defs_s.poly", "Prims.l_and", "Prims.eq2", "Vale.Math.Poly2_s.coerce" ]
[]
false
false
false
false
false
let d (a: poly) : (b: D.poly{poly == D.poly /\ coerce D.poly a == b}) =
reveal_defs (); Vale.Math.Poly2_s.to_poly a
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.smul_rec
val smul_rec (a b m: poly) (n: nat) : Tot (poly & poly & poly) (decreases n)
val smul_rec (a b m: poly) (n: nat) : Tot (poly & poly & poly) (decreases n)
let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 211, "start_col": 0, "start_line": 204 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Prims.Tot ((Vale.Math.Poly2_s.poly * Vale.Math.Poly2_s.poly) * Vale.Math.Poly2_s.poly)
Prims.Tot
[ "total", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Pervasives.Native.Mktuple3", "Vale.Math.Poly2_s.zero", "Prims.bool", "Vale.Math.Poly2_s.shift", "Prims.op_Minus", "Vale.Math.Poly2.Galois.mod_bit1", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2_s.op_String_Access", "FStar.Pervasives.Native.tuple3", "Vale.Math.Poly2.Galois.smul_rec", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
true
false
let rec smul_rec (a b m: poly) (n: nat) : Tot (poly & poly & poly) (decreases n) =
if n = 0 then (zero, a, b) else let p, a, b = smul_rec a b m (n - 1) in let p = p +. (if b.[ 0 ] then a else zero) in let a = mod_bit1 (shift a 1) m in let b = shift b (- 1) in (p, a, b)
false
Lib.ByteSequence.fst
Lib.ByteSequence.uints_to_bytes_le_nat_lemma_
val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i)
val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i)
let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; }
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 665, "start_col": 0, "start_line": 657 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Prims.nat{len * Lib.IntTypes.numbytes t < Prims.pow2 32} -> n: Prims.nat{n < Prims.pow2 (Lib.IntTypes.bits t * len)} -> i: Prims.nat{i < len * Lib.IntTypes.numbytes t} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (Lib.ByteSequence.uints_to_bytes_le (Lib.ByteSequence.nat_to_intseq_le len n)) i == FStar.Seq.Base.index (Lib.ByteSequence.nat_to_bytes_le (len * Lib.IntTypes.numbytes t) n) i)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.l_not", "Lib.IntTypes.uu___is_U1", "Lib.IntTypes.secrecy_level", "Prims.nat", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Prims.pow2", "Lib.IntTypes.bits", "FStar.Calc.calc_finish", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Prims.eq2", "FStar.Seq.Base.index", "Lib.ByteSequence.uints_to_bytes_le", "Lib.ByteSequence.nat_to_intseq_le", "Lib.ByteSequence.nat_to_bytes_le", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.IntTypes.v", "Lib.Sequence.op_String_Access", "Lib.IntTypes.int_t", "Prims.op_Division", "Prims.op_Modulus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.ByteSequence.index_uints_to_bytes_le_aux", "Prims.squash", "Lib.ByteSequence.index_nat_to_intseq_to_bytes_le", "Lib.Sequence.lseq" ]
[]
false
false
true
false
false
let uints_to_bytes_le_nat_lemma_ #t #l len n i =
let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc ( == ) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; ( == ) { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[ i / numbytes t ])) (i % numbytes t); ( == ) { index_nat_to_intseq_to_bytes_le #t #l len n i } Seq.index (nat_to_bytes_le (len * numbytes t) n) i; }
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.fmul_iter
val fmul_iter: f: G.field -> i: nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f
val fmul_iter: f: G.field -> i: nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f
let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 231, "start_col": 0, "start_line": 223 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> i: Prims.nat{i < Lib.IntTypes.bits (GF?.t f) - 1} -> _: Vale.Math.Poly2.Galois.fmul_t f -> Vale.Math.Poly2.Galois.fmul_t f
Prims.Tot
[ "total" ]
[]
[ "Spec.GaloisField.field", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t", "Vale.Math.Poly2.Galois.fmul_t", "Spec.GaloisField.felem", "FStar.Pervasives.Native.Mktuple3", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.shift_right", "Lib.IntTypes.size", "Lib.IntTypes.logxor", "Lib.IntTypes.logand", "Spec.GaloisField.__proj__GF__item__irred", "Lib.IntTypes.shift_left", "Lib.IntTypes.eq_mask", "Spec.GaloisField.one" ]
[]
false
false
false
false
false
let fmul_iter (f: G.field) : i: nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f =
fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_pmul_k_left
val lemma_mul_pmul_k_left (a b: poly) (k: int) (n: nat) (n': int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases (n - n'))
val lemma_mul_pmul_k_left (a b: poly) (k: int) (n: nat) (n': int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases (n - n'))
let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 306, "start_col": 0, "start_line": 298 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> n: Prims.nat -> n': Prims.int -> FStar.Pervasives.Lemma (requires k + 1 <= n' /\ n' <= n) (ensures Vale.Math.Poly2.Galois.sum_of_bools 0 n' (Vale.Math.Poly2.Galois.mul_element_fun a b k) == (Vale.Math.Poly2.Galois.pmul_rec b a n).[ k ]) (decreases n - n')
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.nat", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_left", "Prims.op_Addition", "Prims.bool", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_base", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Galois.sum_of_bools", "Vale.Math.Poly2.Galois.mul_element_fun", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.Galois.pmul_rec", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mul_pmul_k_left (a b: poly) (k: int) (n: nat) (n': int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases (n - n')) =
PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.gmul_rec
val gmul_rec (f: G.field) (a b: G.felem f) (n: nat) : fmul_t f
val gmul_rec (f: G.field) (a b: G.felem f) (n: nat) : fmul_t f
let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 237, "start_col": 0, "start_line": 233 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> n: Prims.nat -> Vale.Math.Poly2.Galois.fmul_t f
Prims.Tot
[ "total" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Pervasives.Native.Mktuple3", "Spec.GaloisField.zero", "Prims.bool", "Vale.Math.Poly2.Galois.fmul_iter", "Vale.Math.Poly2.Galois.fmul_t", "Vale.Math.Poly2.Galois.gmul_rec", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
false
false
let rec gmul_rec (f: G.field) (a b: G.felem f) (n: nat) : fmul_t f =
if n = 0 then (G.zero #f, a, b) else let p, a, b = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b)
false
Lib.ByteSequence.fst
Lib.ByteSequence.nat_from_intseq_be_public_to_secret
val nat_from_intseq_be_public_to_secret: #t:inttype{unsigned t} -> len:size_pos{len * bits t < pow2 32} -> b:lseq (uint_t t PUB) len -> Lemma (nat_from_intseq_be b == nat_from_intseq_be (map secret b))
val nat_from_intseq_be_public_to_secret: #t:inttype{unsigned t} -> len:size_pos{len * bits t < pow2 32} -> b:lseq (uint_t t PUB) len -> Lemma (nat_from_intseq_be b == nat_from_intseq_be (map secret b))
let rec nat_from_intseq_be_public_to_secret #t len b = if len = 1 then begin nat_from_intseq_be_lemma0 b; nat_from_intseq_be_lemma0 (map secret b) end else begin let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_be_public_to_secret #t (len - 1) b1; //assert (nat_from_intseq_be b1 == nat_from_intseq_be (map secret b1)); nat_from_intseq_be_slice_lemma b 1; nat_from_intseq_be_lemma0 (slice b 0 1); //assert (nat_from_intseq_be b == nat_from_intseq_be b1 + pow2 ((len - 1) * bits t) * v b.[0]); nat_from_intseq_be_slice_lemma b_secret 1; nat_from_intseq_be_lemma0 (slice b_secret 0 1); //assert (nat_from_intseq_be b_secret == nat_from_intseq_be b1_secret + pow2 ((len - 1) * bits t) * v b_secret.[0]); //assert (v b.[0] == v b_secret.[0]); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); () end
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 817, "start_col": 0, "start_line": 799 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i) let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; } let uints_to_bytes_le_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_le_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) (nat_to_bytes_le (len * numbytes t) n) val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1)) let index_nat_to_intseq_to_bytes_be #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc (==) { Seq.index (nat_to_bytes_be #l m (v s.[len - 1 - i / m])) (m - (i % m) - 1); == { index_nat_to_intseq_be #U8 #l m (v s.[len - 1 - i / m]) (i % m) } uint (v s.[len - 1 - i / m] / pow2 (8 * (i % m)) % pow2 8); == { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); == { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); == { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); } val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i) let uints_to_bytes_be_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in calc (==) { Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i; == { index_uints_to_bytes_be_aux #t #l len n i } Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_be #t #l len n (len * numbytes t - 1 - i)} Seq.index (nat_to_bytes_be (len * numbytes t) n) i; } let uints_to_bytes_be_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_be_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) (nat_to_bytes_be (len * numbytes t) n) #push-options "--max_fuel 1" let rec nat_from_intseq_le_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_le_inj (Seq.slice b1 1 (length b1)) (Seq.slice b2 1 (length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end let rec nat_from_intseq_be_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_be_inj (Seq.slice b1 0 (length b1 - 1)) (Seq.slice b2 0 (length b2 - 1)); Seq.lemma_split b1 (length b1 - 1); Seq.lemma_split b2 (length b2 - 1) end let lemma_nat_to_from_bytes_be_preserves_value #l b len x = () let lemma_nat_to_from_bytes_le_preserves_value #l b len x = () let lemma_uint_to_bytes_le_preserves_value #t #l x = () let lemma_uint_to_bytes_be_preserves_value #t #l x = () let lemma_nat_from_to_intseq_le_preserves_value #t #l len b = nat_from_intseq_le_inj (nat_to_intseq_le len (nat_from_intseq_le b)) b let lemma_nat_from_to_intseq_be_preserves_value #t #l len b = nat_from_intseq_be_inj (nat_to_intseq_be len (nat_from_intseq_be b)) b let lemma_nat_from_to_bytes_le_preserves_value #l b len = lemma_nat_from_to_intseq_le_preserves_value len b let lemma_nat_from_to_bytes_be_preserves_value #l b len = lemma_nat_from_to_intseq_be_preserves_value len b let lemma_reveal_uint_to_bytes_le #t #l b = () let lemma_reveal_uint_to_bytes_be #t #l b = () let lemma_uint_to_from_bytes_le_preserves_value #t #l i = lemma_reveal_uint_to_bytes_le #t #l (uint_to_bytes_le #t #l i); assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v (uint_from_bytes_le #t #l (uint_to_bytes_le #t #l i))); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i) let lemma_uint_to_from_bytes_be_preserves_value #t #l i = lemma_reveal_uint_to_bytes_be #t #l (uint_to_bytes_be #t #l i); lemma_uint_to_bytes_be_preserves_value #t #l i let lemma_uint_from_to_bytes_le_preserves_value #t #l s = let i = uint_from_bytes_le #t #l s in let s' = uint_to_bytes_le #t #l i in lemma_nat_from_to_bytes_le_preserves_value #l s' (length s'); assert(nat_to_bytes_le #l (length s') (nat_from_bytes_le s') == s'); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i); assert(s' == nat_to_bytes_le #l (length s') (uint_v i)); assert(s' == nat_to_bytes_le #l (length s') (uint_v (uint_from_bytes_le #t #l s))); lemma_reveal_uint_to_bytes_le #t #l s; assert(s' == nat_to_bytes_le #l (length s') (nat_from_bytes_le s)); lemma_nat_from_to_bytes_le_preserves_value #l s (length s) let lemma_uint_from_to_bytes_be_preserves_value #t #l s = let i = uint_from_bytes_be #t #l s in let s' = uint_to_bytes_be #t #l i in lemma_nat_from_to_bytes_be_preserves_value #l s' (length s'); assert(nat_to_bytes_be #l (length s') (nat_from_bytes_be s') == s'); lemma_uint_to_bytes_be_preserves_value #t #l i; assert(nat_from_bytes_be (uint_to_bytes_be #t #l i) == uint_v i); assert(s' == nat_to_bytes_be #l (length s') (uint_v i)); assert(s' == nat_to_bytes_be #l (length s') (uint_v (uint_from_bytes_be #t #l s))); lemma_reveal_uint_to_bytes_be #t #l s; assert(s' == nat_to_bytes_be #l (length s') (nat_from_bytes_be s)); lemma_nat_from_to_bytes_be_preserves_value #l s (length s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_pos{len * Lib.IntTypes.bits t < Prims.pow2 32} -> b: Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.PUB) len -> FStar.Pervasives.Lemma (ensures Lib.ByteSequence.nat_from_intseq_be b == Lib.ByteSequence.nat_from_intseq_be (Lib.Sequence.map Lib.IntTypes.secret b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned", "Lib.IntTypes.size_pos", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Prims.pow2", "Lib.Sequence.lseq", "Lib.IntTypes.uint_t", "Lib.IntTypes.PUB", "Prims.op_Equality", "Prims.int", "Lib.ByteSequence.nat_from_intseq_be_lemma0", "Lib.IntTypes.SEC", "Lib.Sequence.map", "Lib.IntTypes.secret", "Prims.unit", "Prims.bool", "Lib.Sequence.eq_intro", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Lib.Sequence.slice", "Lib.ByteSequence.nat_from_intseq_be_slice_lemma", "Lib.ByteSequence.nat_from_intseq_be_public_to_secret", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.l_Forall", "Prims.nat", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Prims.l_imp" ]
[ "recursion" ]
false
false
true
false
false
let rec nat_from_intseq_be_public_to_secret #t len b =
if len = 1 then (nat_from_intseq_be_lemma0 b; nat_from_intseq_be_lemma0 (map secret b)) else let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_be_public_to_secret #t (len - 1) b1; nat_from_intseq_be_slice_lemma b 1; nat_from_intseq_be_lemma0 (slice b 0 1); nat_from_intseq_be_slice_lemma b_secret 1; nat_from_intseq_be_lemma0 (slice b_secret 0 1); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.pmul_rec
val pmul_rec (a b: poly) (n: nat) : Tot poly (decreases n)
val pmul_rec (a b: poly) (n: nat) : Tot poly (decreases n)
let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 189, "start_col": 0, "start_line": 184 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Prims.Tot Vale.Math.Poly2_s.poly
Prims.Tot
[ "total", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_Equality", "Prims.int", "Vale.Math.Poly2_s.zero", "Prims.bool", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2.Galois.pmul_rec", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
true
false
let rec pmul_rec (a b: poly) (n: nat) : Tot poly (decreases n) =
if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[ n' ] then p +. shift a n' else p
false
GTWP.fst
GTWP.d_bind
val d_bind (#a #b #wc #wf: _) (c: m a D wc) (f: (x: a -> m b D (wf x))) : m b D (bind_wp wc wf)
val d_bind (#a #b #wc #wf: _) (c: m a D wc) (f: (x: a -> m b D (wf x))) : m b D (bind_wp wc wf)
let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ())
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 49, "start_col": 0, "start_line": 47 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: GTWP.m a GTWP.D wc -> f: (x: a -> GTWP.m b GTWP.D (wf x)) -> GTWP.m b GTWP.D (GTWP.bind_wp wc wf)
Prims.Tot
[ "total" ]
[]
[ "GTWP.wp", "GTWP.m", "GTWP.D", "FStar.Universe.raise_val", "Prims.unit", "GTWP.bind_wp", "FStar.Universe.downgrade_val" ]
[]
false
false
false
false
false
let d_bind #a #b #wc #wf (c: m a D wc) (f: (x: a -> m b D (wf x))) : m b D (bind_wp wc wf) =
raise_val (fun () -> let y = downgrade_val c () in downgrade_val (f y) ())
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_pmul_k_base
val lemma_mul_pmul_k_base (a b: poly) (k: int) (n: nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n)
val lemma_mul_pmul_k_base (a b: poly) (k: int) (n: nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n)
let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 296, "start_col": 0, "start_line": 288 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.sum_of_bools 0 n (Vale.Math.Poly2.Galois.mul_element_fun a b k) == (Vale.Math.Poly2.Galois.pmul_rec b a n).[ k ]) (decreases n)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.nat", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_base", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_add_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Galois.sum_of_bools", "Vale.Math.Poly2.Galois.mul_element_fun", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.Galois.pmul_rec", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mul_pmul_k_base (a b: poly) (k: int) (n: nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n) =
PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_element_rec
val lemma_mul_element_rec (a b: poly) (k n: int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k))
val lemma_mul_element_rec (a b: poly) (k n: int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k))
let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 267, "start_col": 0, "start_line": 263 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> n: Prims.int -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.sum_of_bools 0 n (Vale.Math.Poly2.Galois.mul_element_fun a b k) == Vale.Math.Poly2.Galois.sum_of_bools 0 n (Vale.Math.Poly2.Defs_s.mul_element_fun (Vale.Math.Poly2.Galois.d a) (Vale.Math.Poly2.Galois.d b) k))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_mul_element_rec", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "Vale.Math.Poly2_s.reveal_defs", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Galois.sum_of_bools", "Vale.Math.Poly2.Galois.mul_element_fun", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Galois.d", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mul_element_rec (a b: poly) (k n: int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) =
reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.gmul
val gmul (f: G.field) (a b: G.felem f) : G.felem f
val gmul (f: G.field) (a b: G.felem f) : G.felem f
let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 241, "start_col": 0, "start_line": 239 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f
Prims.Tot
[ "total" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Vale.Math.Poly2.Galois.fmul_t", "Vale.Math.Poly2.Galois.gmul_rec", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t" ]
[]
false
false
false
false
false
let gmul (f: G.field) (a b: G.felem f) : G.felem f =
let p, _, _ = gmul_rec f a b (I.bits f.G.t) in p
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_def
val lemma_mul_def (a b: poly) : Lemma (mul_def a b == mul a b)
val lemma_mul_def (a b: poly) : Lemma (mul_def a b == mul a b)
let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 280, "start_col": 0, "start_line": 276 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.mul_def a b == Vale.Math.Poly2_s.mul a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Lemmas.lemma_pointwise_equal", "Vale.Math.Poly2.Galois.mul_def", "Vale.Math.Poly2_s.mul", "Vale.Math.Poly2.Galois.lemma_mul_element", "Prims.unit", "Vale.Math.Poly2_s.reveal_defs", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mul_def (a b: poly) : Lemma (mul_def a b == mul a b) =
reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.fmul
val fmul (f: G.field) (a b: G.felem f) : G.felem f
val fmul (f: G.field) (a b: G.felem f) : G.felem f
let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 253, "start_col": 0, "start_line": 243 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f
Prims.Tot
[ "total" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Lib.IntTypes.int_t", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.SEC", "Lib.IntTypes.logxor", "Lib.IntTypes.logand", "Lib.IntTypes.eq_mask", "Spec.GaloisField.one", "FStar.Pervasives.Native.tuple3", "Lib.LoopCombinators.repeati", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Vale.Math.Poly2.Galois.fmul_iter", "FStar.Pervasives.Native.Mktuple3", "Spec.GaloisField.zero" ]
[]
false
false
false
false
false
let fmul (f: G.field) (a b: G.felem f) : G.felem f =
let one = G.one #f in let zero = G.zero #f in let p, a, b = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p
false
Lib.ByteSequence.fst
Lib.ByteSequence.nat_from_intseq_be_slice_lemma_
val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i))
val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i))
let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 411, "start_col": 0, "start_line": 399 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Sequence.lseq (Lib.IntTypes.int_t t l) len -> i: Prims.nat{i <= len} -> FStar.Pervasives.Lemma (ensures Lib.ByteSequence.nat_from_intseq_be_ b == Lib.ByteSequence.nat_from_intseq_be_ (Lib.Sequence.slice b i len) + Prims.pow2 ((len - i) * Lib.IntTypes.bits t) * Lib.ByteSequence.nat_from_intseq_be_ (Lib.Sequence.slice b 0 i)) (decreases len - i)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned", "Lib.IntTypes.secrecy_level", "Lib.IntTypes.size_nat", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.l_or", "Lib.IntTypes.max_size_t", "Lib.ByteSequence.nat_from_intseq_slice_lemma_aux", "Lib.IntTypes.v", "Lib.Sequence.op_String_Access", "Lib.ByteSequence.nat_from_intseq_be_", "Lib.Sequence.slice", "Lib.IntTypes.bits", "Prims.op_Subtraction", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Lib.ByteSequence.nat_from_intseq_be_slice_lemma_", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.index" ]
[ "recursion" ]
false
false
true
false
false
let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i =
if len = 0 then () else if i = len then () else let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[ i ]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[ i ]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_pmul
val lemma_mul_pmul (a b: poly) : Lemma (mul_def a b == pmul b a)
val lemma_mul_pmul (a b: poly) : Lemma (mul_def a b == pmul b a)
let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 331, "start_col": 0, "start_line": 328 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.mul_def a b == Vale.Math.Poly2.Galois.pmul b a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Lemmas.lemma_pointwise_equal", "Vale.Math.Poly2.Galois.mul_def", "Vale.Math.Poly2.Galois.pmul", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mul_pmul (a b: poly) : Lemma (mul_def a b == pmul b a) =
PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mmul_pmul
val lemma_mmul_pmul (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m)
val lemma_mmul_pmul (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m)
let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 362, "start_col": 0, "start_line": 356 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2.Galois.poly_length m > 0 /\ n >= Vale.Math.Poly2.Galois.poly_length b) (ensures Vale.Math.Poly2_s.mod (Vale.Math.Poly2.Galois.mmul a b m n) m == Vale.Math.Poly2_s.mod (Vale.Math.Poly2.Galois.pmul a b) m)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_Equality", "Vale.Math.Poly2.Galois.poly_length", "Vale.Math.Poly2.Galois.lemma_mmul_pmul_rec", "Prims.bool", "Vale.Math.Poly2.Galois.lemma_mmul_pmul", "Prims.op_Subtraction", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_GreaterThanOrEqual", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2_s.mod", "Vale.Math.Poly2.Galois.mmul", "Vale.Math.Poly2.Galois.pmul", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mmul_pmul (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) =
PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1)
false
Lib.ByteSequence.fst
Lib.ByteSequence.uints_to_bytes_be_nat_lemma_
val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i)
val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i)
let uints_to_bytes_be_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in calc (==) { Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i; == { index_uints_to_bytes_be_aux #t #l len n i } Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_be #t #l len n (len * numbytes t - 1 - i)} Seq.index (nat_to_bytes_be (len * numbytes t) n) i; }
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 713, "start_col": 0, "start_line": 705 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i) let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; } let uints_to_bytes_le_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_le_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) (nat_to_bytes_le (len * numbytes t) n) val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1)) let index_nat_to_intseq_to_bytes_be #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc (==) { Seq.index (nat_to_bytes_be #l m (v s.[len - 1 - i / m])) (m - (i % m) - 1); == { index_nat_to_intseq_be #U8 #l m (v s.[len - 1 - i / m]) (i % m) } uint (v s.[len - 1 - i / m] / pow2 (8 * (i % m)) % pow2 8); == { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); == { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); == { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); } val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Prims.nat{len * Lib.IntTypes.numbytes t < Prims.pow2 32} -> n: Prims.nat{n < Prims.pow2 (Lib.IntTypes.bits t * len)} -> i: Prims.nat{i < len * Lib.IntTypes.numbytes t} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (Lib.ByteSequence.uints_to_bytes_be (Lib.ByteSequence.nat_to_intseq_be len n)) i == FStar.Seq.Base.index (Lib.ByteSequence.nat_to_bytes_be (len * Lib.IntTypes.numbytes t) n) i)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.l_not", "Lib.IntTypes.uu___is_U1", "Lib.IntTypes.secrecy_level", "Prims.nat", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Prims.pow2", "Lib.IntTypes.bits", "FStar.Calc.calc_finish", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Prims.eq2", "FStar.Seq.Base.index", "Lib.ByteSequence.uints_to_bytes_be", "Lib.ByteSequence.nat_to_intseq_be", "Lib.ByteSequence.nat_to_bytes_be", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.IntTypes.v", "Lib.Sequence.op_String_Access", "Lib.IntTypes.int_t", "Prims.op_Division", "Prims.op_Modulus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.ByteSequence.index_uints_to_bytes_be_aux", "Prims.squash", "Lib.ByteSequence.index_nat_to_intseq_to_bytes_be", "Prims.op_Subtraction", "Lib.Sequence.lseq" ]
[]
false
false
true
false
false
let uints_to_bytes_be_nat_lemma_ #t #l len n i =
let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in calc ( == ) { Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i; ( == ) { index_uints_to_bytes_be_aux #t #l len n i } Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[ i / numbytes t ])) (i % numbytes t); ( == ) { index_nat_to_intseq_to_bytes_be #t #l len n (len * numbytes t - 1 - i) } Seq.index (nat_to_bytes_be (len * numbytes t) n) i; }
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_pmul_degree
val lemma_pmul_degree (a b: poly) (n: nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n)
val lemma_pmul_degree (a b: poly) (n: nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n)
let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 286, "start_col": 0, "start_line": 282 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.poly_length (Vale.Math.Poly2.Galois.pmul_rec a b n) <= Vale.Math.Poly2.Galois.poly_length a + n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_pmul_degree", "Prims.op_Subtraction", "Prims.bool", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.Math.Poly2.Galois.poly_length", "Vale.Math.Poly2.Galois.pmul_rec", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pmul_degree (a b: poly) (n: nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) =
if n > 0 then lemma_pmul_degree a b (n - 1)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_element
val lemma_mul_element (a b: poly) (k: int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k)
val lemma_mul_element (a b: poly) (k: int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k)
let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 274, "start_col": 0, "start_line": 269 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.mul_element a b k == Vale.Math.Poly2.Defs_s.mul_element (Vale.Math.Poly2.Galois.d a) (Vale.Math.Poly2.Galois.d b) k )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.unit", "Vale.Math.Poly2.Galois.lemma_mul_element_rec", "Prims.op_Addition", "Vale.Math.Poly2_s.reveal_defs", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Galois.mul_element", "Vale.Math.Poly2.Defs_s.mul_element", "Vale.Math.Poly2.Galois.d", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mul_element (a b: poly) (k: int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) =
reveal_defs (); lemma_mul_element_rec a b k (k + 1); ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_pmul_k_right
val lemma_mul_pmul_k_right (a b: poly) (k: int) (n n': nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n')
val lemma_mul_pmul_k_right (a b: poly) (k: int) (n n': nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n')
let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 316, "start_col": 0, "start_line": 308 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> n: Prims.nat -> n': Prims.nat -> FStar.Pervasives.Lemma (requires n == Vale.Math.Poly2.Galois.poly_length a /\ n <= n') (ensures Vale.Math.Poly2.Galois.sum_of_bools 0 n' (Vale.Math.Poly2.Galois.mul_element_fun a b k) == (Vale.Math.Poly2.Galois.pmul_rec b a n).[ k ]) (decreases n')
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.nat", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_right", "Prims.op_Subtraction", "Prims.bool", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_base", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_and", "Prims.eq2", "Vale.Math.Poly2.Galois.poly_length", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Vale.Math.Poly2.Galois.sum_of_bools", "Vale.Math.Poly2.Galois.mul_element_fun", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.Galois.pmul_rec", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mul_pmul_k_right (a b: poly) (k: int) (n n': nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[ k ]) (decreases n') =
PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mod_bit1
val lemma_mod_bit1 (a m: poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m)
val lemma_mod_bit1 (a m: poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m)
let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 383, "start_col": 0, "start_line": 364 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2.Galois.poly_length a <= Vale.Math.Poly2.Galois.poly_length m /\ 0 <= Vale.Math.Poly2_s.degree m) (ensures Vale.Math.Poly2.Galois.mod_bit1 a m == a %. m)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.op_LessThan", "Vale.Math.Poly2.Galois.poly_length", "Vale.Math.Poly2.Lemmas.lemma_mod_small", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2.lemma_add_zero", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2.Lemmas.lemma_mod_cancel", "Vale.Math.Poly2.Lemmas.lemma_mod_distribute", "Vale.Math.Poly2.lemma_degree", "Prims.nat", "Vale.Math.Poly2.Lemmas.lemma_add_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.Math.Poly2_s.degree", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Galois.mod_bit1", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_mod_bit1 (a m: poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) =
PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else (lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); PL.lemma_mod_small (a +. m) m; ())
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mmul_smul_rec
val lemma_mmul_smul_rec (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (- n)) /\ mmul a b m n == mmul a b m n %. m)
val lemma_mmul_smul_rec (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (- n)) /\ mmul a b m n == mmul a b m n %. m)
let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 444, "start_col": 0, "start_line": 413 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree m >= 0 /\ Vale.Math.Poly2_s.degree a < Vale.Math.Poly2_s.degree m) (ensures Vale.Math.Poly2.Galois.smul_rec a b m n == (Vale.Math.Poly2.Galois.mmul a b m n, Vale.Math.Poly2_s.shift a n %. m, Vale.Math.Poly2_s.shift b (- n)) /\ Vale.Math.Poly2.Galois.mmul a b m n == Vale.Math.Poly2.Galois.mmul a b m n %. m)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.unit", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2_s.shift", "Prims.op_Minus", "Prims.op_GreaterThan", "Vale.Math.Poly2.lemma_add_zero", "Vale.Math.Poly2.Galois.lemma_mod_bit1", "Vale.Math.Poly2.Lemmas.lemma_mod_mod", "Vale.Math.Poly2.Lemmas.lemma_mod_distribute", "Vale.Math.Poly2.Lemmas.lemma_shift_mod", "Vale.Math.Poly2.Lemmas.lemma_shift_shift", "Vale.Math.Poly2.Galois.lemma_mmul_smul_rec", "FStar.Pervasives.Native.tuple3", "Vale.Math.Poly2.Galois.smul_rec", "Prims.int", "Prims.op_Subtraction", "Prims.bool", "Vale.Math.Poly2.Lemmas.lemma_mod_small", "Vale.Math.Poly2_s.zero", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Vale.Math.Poly2_s.degree", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.Mktuple3", "Vale.Math.Poly2.Galois.mmul", "Vale.Math.Poly2.op_Percent_Dot", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mmul_smul_rec (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (- n)) /\ mmul a b m n == mmul a b m n %. m) =
PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let p0, a0, b0 = smul_rec a b m n in if n > 0 then (let n1 = n - 1 in let p1, a1, b1 = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (- n1) (- 1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; lemma_add_zero p1; ()); lemma_equal b0 (shift b (- n)); ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul_pmul_k
val lemma_mul_pmul_k (a b: poly) (k: int) : Lemma ((mul_def a b).[ k ] == (pmul b a).[ k ])
val lemma_mul_pmul_k (a b: poly) (k: int) : Lemma ((mul_def a b).[ k ] == (pmul b a).[ k ])
let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 326, "start_col": 0, "start_line": 318 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> k: Prims.int -> FStar.Pervasives.Lemma (ensures (Vale.Math.Poly2.Galois.mul_def a b).[ k ] == (Vale.Math.Poly2.Galois.pmul b a).[ k ])
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Prims.op_Equality", "Prims.op_Addition", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_base", "Prims.bool", "Prims.op_GreaterThan", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_left", "Vale.Math.Poly2.Galois.lemma_mul_pmul_k_right", "Prims.unit", "Vale.Math.Poly2.Galois.lemma_pmul_degree", "Prims.nat", "Vale.Math.Poly2.Galois.poly_length", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.Galois.mul_def", "Vale.Math.Poly2.Galois.pmul", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_mul_pmul_k (a b: poly) (k: int) : Lemma ((mul_def a b).[ k ] == (pmul b a).[ k ]) =
PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1)
false
GTWP.fst
GTWP.app
val app (#a #b #i #wp: _) (f: (a -> GTD b i wp)) (x: a) : GTD b i wp
val app (#a #b #i #wp: _) (f: (a -> GTD b i wp)) (x: a) : GTD b i wp
let app #a #b #i #wp (f : a -> GTD b i wp) (x : a) : GTD b i wp = f x
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 69, "end_line": 137, "start_col": 0, "start_line": 137 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) unfold let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x) effect Gtd (a:Type) (i:idx) = GTD a i (null_wp a) let rec map #a #b #i (f : a -> Gtd b i) (xs : list a) : Gtd (list b) i (* by (explode (); dump "") *) = match xs with | [] -> [] | x::xs -> (f x)::(map f xs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: a -> GTWP.GTD b) -> x: a -> GTWP.GTD b
GTWP.GTD
[]
[]
[ "GTWP.idx", "GTWP.wp" ]
[]
false
true
false
false
false
let app #a #b #i #wp (f: (a -> GTD b i wp)) (x: a) : GTD b i wp =
f x
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mmul_smul
val lemma_mmul_smul (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n)
val lemma_mmul_smul (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n)
let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 450, "start_col": 0, "start_line": 446 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree m >= 0 /\ Vale.Math.Poly2_s.degree a < Vale.Math.Poly2_s.degree m) (ensures Vale.Math.Poly2.Galois.smul a b m n == Vale.Math.Poly2.Galois.mmul a b m n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Vale.Math.Poly2.Galois.lemma_mmul_smul_rec", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Vale.Math.Poly2_s.degree", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Galois.smul", "Vale.Math.Poly2.Galois.mmul", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mmul_smul (a b m: poly) (n: nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) =
lemma_mmul_smul_rec a b m n
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mmul_pmul_rec
val lemma_mmul_pmul_rec (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m)
val lemma_mmul_pmul_rec (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m)
let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 354, "start_col": 0, "start_line": 333 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2.Galois.poly_length m > 0) (ensures Vale.Math.Poly2_s.mod (Vale.Math.Poly2.Galois.mmul a b m n) m == Vale.Math.Poly2_s.mod (Vale.Math.Poly2.Galois.pmul_rec a b n) m)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_GreaterThan", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_mod_mod", "Vale.Math.Poly2.Lemmas.lemma_mod_distribute", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2_s.shift", "Prims._assert", "Prims.eq2", "Vale.Math.Poly2_s.mod", "Vale.Math.Poly2.Galois.lemma_mmul_pmul_rec", "Prims.op_Subtraction", "Vale.Math.Poly2.Galois.pmul_rec", "Vale.Math.Poly2.Galois.mmul", "Prims.int", "Prims.bool", "Prims.b2t", "Vale.Math.Poly2.Galois.poly_length", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mmul_pmul_rec (a b m: poly) (n: nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) =
if n > 0 then (let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; ())
false
GTWP.fst
GTWP.labs0
val labs0 (#i: _) (n: int) : Gtd int i
val labs0 (#i: _) (n: int) : Gtd int i
let labs0 #i (n:int) : Gtd int i = if n < 0 then -n else n
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 157, "start_col": 0, "start_line": 154 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) unfold let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x) effect Gtd (a:Type) (i:idx) = GTD a i (null_wp a) let rec map #a #b #i (f : a -> Gtd b i) (xs : list a) : Gtd (list b) i (* by (explode (); dump "") *) = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) let app #a #b #i #wp (f : a -> GTD b i wp) (x : a) : GTD b i wp = f x open FStar.Tactics.V2 let rec appn #a #i (n:nat) (f : a -> Gtd a i) (x : a) : Gtd a i = match n with | 0 -> x | _ -> begin appn (n-1) f (f x) end // explodes //[@@expect_failure] //let test #a #i (n:int) : Gtd nat i = // let r = app abs n in // r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.int -> GTWP.Gtd Prims.int
GTWP.Gtd
[]
[]
[ "GTWP.idx", "Prims.int", "Prims.op_LessThan", "Prims.op_Minus", "Prims.bool" ]
[]
false
true
false
false
false
let labs0 #i (n: int) : Gtd int i =
if n < 0 then - n else n
false
GTWP.fst
GTWP.coerce
val coerce (#a #b: _) (x: a{a == b}) : b
val coerce (#a #b: _) (x: a{a == b}) : b
let coerce #a #b (x:a{a == b}) : b = x
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 13, "start_col": 0, "start_line": 13 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a{a == b} -> b
Prims.Tot
[ "total" ]
[]
[ "Prims.eq2" ]
[]
false
false
false
false
false
let coerce #a #b (x: a{a == b}) : b =
x
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.mmul
val mmul (a b m: poly) (n: nat) : Tot poly (decreases n)
val mmul (a b m: poly) (n: nat) : Tot poly (decreases n)
let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 199, "start_col": 0, "start_line": 194 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> m: Vale.Math.Poly2_s.poly -> n: Prims.nat -> Prims.Tot Vale.Math.Poly2_s.poly
Prims.Tot
[ "total", "" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.op_Equality", "Prims.int", "Vale.Math.Poly2_s.zero", "Prims.bool", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2.Galois.mmul", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
true
false
let rec mmul (a b m: poly) (n: nat) : Tot poly (decreases n) =
if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[ n' ] then p +. (shift a n' %. m) else p
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mod_shift1
val lemma_mod_shift1 (a irred: poly) (k: nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[ k - 1 ]))
val lemma_mod_shift1 (a irred: poly) (k: nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[ k - 1 ]))
let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 411, "start_col": 0, "start_line": 385 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
a: Vale.Math.Poly2_s.poly -> irred: Vale.Math.Poly2_s.poly -> k: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2_s.degree a < k /\ Vale.Math.Poly2_s.degree irred < k) (ensures Vale.Math.Poly2.Galois.mod_bit1 (Vale.Math.Poly2_s.shift a 1) (Vale.Math.Poly2_s.monomial k +. irred) == Vale.Math.Poly2.Galois.mod_shift1 a irred k /\ (Vale.Math.Poly2_s.shift a (1 - k) == Vale.Math.Poly2_s.one <==> a.[ k - 1 ]))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2_s.poly", "Prims.nat", "Prims.unit", "Vale.Math.Poly2_s.op_String_Access", "Prims.op_Subtraction", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2_s.one", "Prims.bool", "Vale.Math.Poly2.Galois.mod_bit1", "Vale.Math.Poly2.Galois.mod_shift1", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2_s.monomial", "Prims._assert", "Prims.eq2", "Vale.Math.Poly2.Lemmas.lemma_mod_monomial", "Prims.b2t", "Vale.Math.Poly2.Lemmas.lemma_one_define", "Vale.Math.Poly2.Lemmas.lemma_monomial_define", "Vale.Math.Poly2.Lemmas.lemma_shift_define_all", "Vale.Math.Poly2.Lemmas.lemma_add_define_all", "Vale.Math.Poly2.Lemmas.lemma_index_all", "Vale.Math.Poly2.op_Percent_Dot", "Prims.l_and", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree", "Prims.squash", "Prims.l_iff", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_mod_shift1 (a irred: poly) (k: nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[ k - 1 ])) =
let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[ k ]); PL.lemma_mod_monomial (shift a 1) k; if a.[ k - 1 ] then (lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); ()) else (assert ((shift a (1 - k)).[ 0 ] == false); ()); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[ k - 1 ] then lemma_equal (shift a (1 - k)) one; ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_eqmask_and
val lemma_eqmask_and (t: I.inttype{Lib.IntTypes.unsigned t}) (a b c: I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0))
val lemma_eqmask_and (t: I.inttype{Lib.IntTypes.unsigned t}) (a b c: I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0))
let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 461, "start_col": 0, "start_line": 452 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
t: Lib.IntTypes.inttype{Lib.IntTypes.unsigned t} -> a: Lib.IntTypes.uint_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.uint_t t Lib.IntTypes.SEC -> c: Lib.IntTypes.uint_t t Lib.IntTypes.SEC -> FStar.Pervasives.Lemma (requires ~(t == Lib.IntTypes.U1)) (ensures Lib.IntTypes.v (Lib.IntTypes.logand (Lib.IntTypes.eq_mask a b) c) == (match Lib.IntTypes.v a = Lib.IntTypes.v b with | true -> Lib.IntTypes.v c | _ -> 0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.unit", "FStar.UInt.logand_lemma_2", "Lib.IntTypes.bits", "Lib.IntTypes.v", "FStar.UInt.logand_lemma_1", "FStar.UInt.logand_commutative", "Lib.IntTypes.eq_mask", "Vale.Math.Poly2.Galois.IntTypes.define_logand", "Vale.Math.Poly2.Galois.IntTypes.define_eq_mask", "Prims.l_not", "Prims.eq2", "Lib.IntTypes.U1", "Prims.squash", "Prims.int", "Lib.IntTypes.logand", "Prims.op_Equality", "Lib.IntTypes.range_t", "Prims.bool", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_eqmask_and (t: I.inttype{Lib.IntTypes.unsigned t}) (a b c: I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) =
GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); ()
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_mul
val lemma_mul (f:G.field) (a b:G.felem f) : Lemma (requires True) (ensures to_poly (G.fmul a b) == (to_poly a *. to_poly b) %. (irred_poly f)) [SMTPat (to_poly (G.fmul a b))]
val lemma_mul (f:G.field) (a b:G.felem f) : Lemma (requires True) (ensures to_poly (G.fmul a b) == (to_poly a *. to_poly b) %. (irred_poly f)) [SMTPat (to_poly (G.fmul a b))]
let lemma_mul f a b = let G.GF t irred = f in let n = I.bits t in let pa = to_poly a in let pb = to_poly b in let m = irred_poly f in lemma_mul_commute pa pb; lemma_mul_def pb pa; lemma_mul_pmul pb pa; lemma_mmul_pmul pa pb m n; lemma_mmul_smul pa pb m n; lemma_smul_fmul f a b; lemma_fmul_gmul f a b; lemma_fmul_fmul f a b; PL.lemma_mod_small (to_poly (G.fmul a b)) m; ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 591, "start_col": 0, "start_line": 576 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); () #reset-options "--z3rlimit 20" let rec lemma_smul_gmul_rec (f:G.field) (e1 e2:G.felem f) (n:nat) : Lemma ( let (p, a, b) = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) = let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then ( lemma_smul_gmul_rec f e1 e2 (n - 1); let (sp, sa, sb) = smul_rec a b m (n - 1) in let (gp, ga, gb) = gmul_rec f e1 e2 (n - 1) in //assert (to_poly gp == sp); //assert (to_poly ga == sa); //assert (to_poly gb == sb); let sp' = sp +. (if sb.[0] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in // mod_bit1 is equivalent to mod in this case let sb' = shift sb (-1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[k - 1] then m_lo else zero in let ssa' = ssa +. ssa_add in //assert (sa' == ssa'); let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[0] then lemma_equal (sb &. one) one; //assert (sb.[0] <==> I.v (I.logand gb (G.one #f)) = I.v (G.one #f)); lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); //assert (to_poly gp' == sp'); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; //assert (to_poly f.G.irred == m_lo); lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); //assert (to_poly carry_irred == ssa_add); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); //assert (to_poly ga_shift == ssa); //assert (to_poly ga' == ssa'); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); //assert (to_poly gb' == sb'); () ) let lemma_smul_fmul (f:G.field) (e1 e2:G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t)) = let G.GF t irred = f in let n = I.bits t in lemma_smul_gmul_rec f e1 e2 n let lemma_fmul_gmul (f:G.field) (a b:G.felem f) : Lemma (fmul f a b == gmul f a b) = let pred (n:nat) (pab:(fmul_t f)) : Type0 = gmul_rec f a b n == pab in let _ = Lib.LoopCombinators.repeati_inductive' (I.bits f.G.t - 1) pred (fmul_iter f) (G.zero #f, a, b) in () #reset-options "--initial_ifuel 1" // HACK: It would be easier if G.fmul were already defined more like fmul (passing repeati a named function rather than a lambda) let lemma_fmul_fmul (f:G.field) (a b:G.felem f) : Lemma (G.fmul a b == fmul f a b) = let repeati = Lib.LoopCombinators.repeati in let acc0 = (G.zero #f, a, b) in let rec lem (n:nat{n < I.bits f.G.t}) (f1:(i:nat{i < n} -> fmul_t f -> fmul_t f)) : Lemma (requires (forall (i:nat{i < n}) (pab:fmul_t f). f1 i pab == fmul_iter f i pab)) (ensures repeati n (fmul_iter f) acc0 == repeati n f1 acc0) [SMTPat (repeati n f1 acc0)] = if n = 0 then ( let pred (n:nat) (pab:(fmul_t f)) : Type0 = n == 0 ==> pab == acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred (fmul_iter f) acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred f1 acc0 in () ) else ( lem (n - 1) f1; Lib.LoopCombinators.unfold_repeati n (fmul_iter f) acc0 (n - 1); Lib.LoopCombinators.unfold_repeati n f1 acc0 (n - 1); assert (repeati n (fmul_iter f) acc0 == repeati n f1 acc0); () ) in ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.to_poly (Spec.GaloisField.fmul a b) == Vale.Math.Poly2.Galois.to_poly a *. Vale.Math.Poly2.Galois.to_poly b %. Vale.Math.Poly2.Galois.irred_poly f) [SMTPat (Vale.Math.Poly2.Galois.to_poly (Spec.GaloisField.fmul a b))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.op_disEquality", "Lib.IntTypes.U1", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.unit", "Vale.Math.Poly2.Lemmas.lemma_mod_small", "Vale.Math.Poly2.Galois.to_poly", "Spec.GaloisField.fmul", "Vale.Math.Poly2.Galois.lemma_fmul_fmul", "Vale.Math.Poly2.Galois.lemma_fmul_gmul", "Vale.Math.Poly2.Galois.lemma_smul_fmul", "Vale.Math.Poly2.Galois.lemma_mmul_smul", "Vale.Math.Poly2.Galois.lemma_mmul_pmul", "Vale.Math.Poly2.Galois.lemma_mul_pmul", "Vale.Math.Poly2.Galois.lemma_mul_def", "Vale.Math.Poly2.lemma_mul_commute", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Galois.irred_poly", "Prims.int", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let lemma_mul f a b =
let G.GF t irred = f in let n = I.bits t in let pa = to_poly a in let pb = to_poly b in let m = irred_poly f in lemma_mul_commute pa pb; lemma_mul_def pb pa; lemma_mul_pmul pb pa; lemma_mmul_pmul pa pb m n; lemma_mmul_smul pa pb m n; lemma_smul_fmul f a b; lemma_fmul_gmul f a b; lemma_fmul_fmul f a b; PL.lemma_mod_small (to_poly (G.fmul a b)) m; ()
false
Vale.Curve25519.FastMul_helpers.fst
Vale.Curve25519.FastMul_helpers.lemma_sqr
val lemma_sqr (a:int) (a0 a1 a2 a3 r8 r9 r10 r11 r12 r13 rax rcx r8' r9' r10' r11' r12' r13' r14' d0 d1 d2 d3 d4 d5 d6 d7:nat64) (cf:bit) : Lemma (requires a = pow2_four a0 a1 a2 a3 /\ pow2_six r8 r9 r10 r11 r12 r13 == pow2_five (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3) (mul_nats a1 a3) (mul_nats a2 a3) /\ pow2_64 * rcx + rax == a1 * a2 /\ pow2_seven r8' r9' r10' r11' r12' r13' r14' == pow2_six (2*r8) (2*r9) (2*(r10+rax)) (2*(r11+rcx)) (2*r12) (2*r13) /\ pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14') (ensures a*a == pow2_eight d0 d1 d2 d3 d4 d5 d6 d7)
val lemma_sqr (a:int) (a0 a1 a2 a3 r8 r9 r10 r11 r12 r13 rax rcx r8' r9' r10' r11' r12' r13' r14' d0 d1 d2 d3 d4 d5 d6 d7:nat64) (cf:bit) : Lemma (requires a = pow2_four a0 a1 a2 a3 /\ pow2_six r8 r9 r10 r11 r12 r13 == pow2_five (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3) (mul_nats a1 a3) (mul_nats a2 a3) /\ pow2_64 * rcx + rax == a1 * a2 /\ pow2_seven r8' r9' r10' r11' r12' r13' r14' == pow2_six (2*r8) (2*r9) (2*(r10+rax)) (2*(r11+rcx)) (2*r12) (2*r13) /\ pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14') (ensures a*a == pow2_eight d0 d1 d2 d3 d4 d5 d6 d7)
let lemma_sqr a a0 a1 a2 a3 r8 r9 r10 r11 r12 r13 rax rcx r8' r9' r10' r11' r12' r13' r14' d0 d1 d2 d3 d4 d5 d6 d7 cf = assert (a < pow2_256); // PASSES assert_norm (pow2_256 == pow2 256); // PASSES pow2_plus 256 256; lemma_mul_pow2_bound 256 a a; assert (a*a < pow2_256 * pow2_256); // PASSES assert (cf = 1 ==> pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf >= pow2_512); assert_by_tactic ((pow2_four a0 a1 a2 a3) * (pow2_four a0 a1 a2 a3) == pow2_seven (mul_nats a0 a0) (2*(mul_nats a0 a1)) (2*(mul_nats a0 a2) + (mul_nats a1 a1)) (2*((mul_nats a0 a3) + (mul_nats a1 a2))) (2*(mul_nats a1 a3) + (mul_nats a2 a2)) (2*(mul_nats a2 a3)) (mul_nats a3 a3)) (fun _ -> int_canon (); trefl(); qed ()); let lhs:int = pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14' in let squares = pow2_eight (mul_nats a0 a0) 0 (mul_nats a1 a1) 0 (mul_nats a2 a2) 0 (mul_nats a3 a3) 0 in let regs = pow2_eight 0 r8' r9' r10' r11' r12' r13' r14' in let rhs:int = squares + regs in assert (2*(mul_nats a0 a3 + a1*a2) >= 0); calc (eq2 #int) { pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14'; (eq2 #int ) { _ by (int_canon()) } pow2_eight (mul_nats a0 a0) 0 (mul_nats a1 a1) 0 (mul_nats a2 a2) 0 (mul_nats a3 a3) 0 + pow2_eight 0 r8' r9' r10' r11' r12' r13' r14'; (eq2 #int) { calc (eq2 #int) { pow2_eight 0 r8' r9' r10' r11' r12' r13' r14'; (eq2 #int) { lemma_shift_pow2_eight r8' r9' r10' r11' r12' r13' r14' } pow2_64 * pow2_six (2*r8) (2*r9) (2*(r10+rax)) (2*(r11+rcx)) (2*r12) (2*r13); (eq2 #int) { calc (eq2 #int) { pow2_six (2*r8) (2*r9) (2*(r10+rax)) (2*(r11+rcx)) (2*r12) (2*r13); (eq2 #int) { lemma_dbl_pow2_six r8 r9 (r10+rax) (r11+rcx) r12 r13 } 2 * pow2_six r8 r9 (r10+rax) (r11+rcx) r12 r13; (eq2 #int) { () } // calc // (eq2 #int) { // pow2_six r8 r9 (r10+rax) (r11+rcx) r12 r13; // (eq2 #int) { _ by (int_canon()) } // pow2_six r8 r9 r10 r11 r12 r13 + pow2_six 0 0 rax rcx 0 0; // (eq2 #int) { admit() } // pow2_six (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3) (mul_nats a1 a3) (mul_nats a2 a3) 0 // + pow2_six 0 0 rax rcx 0 0; // (eq2 #int) { // calc // (eq2 #int) { // pow2_six 0 0 rax rcx 0 0; // (eq2 #int) { () } // pow2_six 0 0 (a1*a2) 0 0 0; // } // } // pow2_six (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3) (mul_nats a1 a3) (mul_nats a2 a3) 0 // + pow2_six 0 0 (a1*a2) 0 0 0; // (eq2 #int) { admit () } // pow2_six (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3 + a1*a2) (mul_nats a1 a3) (mul_nats a2 a3) 0; // } // } 2*pow2_six (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3 + a1*a2) (mul_nats a1 a3) (mul_nats a2 a3) 0; (eq2 #int) { () } pow2_six (2*(mul_nats a0 a1)) (2*(mul_nats a0 a2)) (2*(mul_nats a0 a3 + a1*a2)) (2*(mul_nats a1 a3)) (2*(mul_nats a2 a3)) 0; } } pow2_64 * pow2_six (2*(mul_nats a0 a1)) (2*(mul_nats a0 a2)) (2*(mul_nats a0 a3 + a1*a2)) (2*(mul_nats a1 a3)) (2*(mul_nats a2 a3)) 0; (eq2 #int) { () } pow2_seven 0 (2*(mul_nats a0 a1)) (2*(mul_nats a0 a2)) (2*(mul_nats a0 a3 + a1*a2)) (2*(mul_nats a1 a3)) (2*(mul_nats a2 a3)) 0; } } pow2_eight (mul_nats a0 a0) (2*(mul_nats a0 a1)) ((2*(mul_nats a0 a2)) + mul_nats a1 a1) (2*(mul_nats a0 a3 + a1*a2)) ((2*(mul_nats a1 a3)) + mul_nats a2 a2) (2*(mul_nats a2 a3)) (mul_nats a3 a3) 0; (eq2 #int) { () } pow2_seven (mul_nats a0 a0) (2*(mul_nats a0 a1)) ((2*(mul_nats a0 a2)) + mul_nats a1 a1) (2*(mul_nats a0 a3 + a1*a2)) ((2*(mul_nats a1 a3)) + mul_nats a2 a2) (2*(mul_nats a2 a3)) (mul_nats a3 a3); }; assert (pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == a*a); // PASSES //assert (cf == 0); let ultimate_rhs:int = pow2_eight d0 d1 d2 d3 d4 d5 d6 d7 in assert_by_tactic (pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == ultimate_rhs) int_canon
{ "file_name": "vale/code/crypto/ecc/curve25519/Vale.Curve25519.FastMul_helpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 83, "end_line": 410, "start_col": 0, "start_line": 304 }
module Vale.Curve25519.FastMul_helpers open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Mul open FStar.Tactics open FStar.Tactics.CanonCommSemiring open Vale.Curve25519.Fast_defs open Vale.Curve25519.Fast_lemmas_internal open FStar.Math.Lemmas #reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'" #push-options "--z3rlimit 10" let lemma_mul_pow2_bound (b:nat{b > 1}) (x y:natN (pow2 b)) : Lemma (x * y < pow2 (2*b) - 1 /\ x * y <= pow2 (2*b) - 2*pow2(b) + 1) = lemma_mul_bounds_le x (pow2 b - 1) y (pow2 b -1); pow2_plus b b; assert ( (pow2 b - 1) * (pow2 b -1) = pow2 (2*b) - 2*pow2(b) + 1) #pop-options let lemma_mul_bound64 (x y:nat64) : Lemma (x * y < pow2_128 - 1 /\ x * y <= pow2_128 - 2*pow2_64 + 1) = assert_norm (pow2 64 == pow2_64); assert_norm (pow2 128 == pow2_128); lemma_mul_pow2_bound 64 x y (* Intel manual mentions this fact *) let lemma_intel_prod_sum_bound (w x y z:nat64) : Lemma (w * x + y + z < pow2_128) = lemma_mul_bound64 w x let lemma_prod_bounds (dst_hi dst_lo x y:nat64) : Lemma (requires pow2_64 * dst_hi + dst_lo == x * y) (ensures dst_hi < pow2_64 - 1 /\ (dst_hi < pow2_64 - 2 \/ dst_lo <= 1)) = let result = x * y in lemma_div_mod result pow2_64; //assert (result = pow2_64 * (result / pow2_64) + result % pow2_64); //assert (result % pow2_64 == dst_lo); //assert (result / pow2_64 == dst_hi); lemma_mul_bound64 x y let lemma_double_bound (x:nat64) : Lemma (add_wrap x x < pow2_64 - 1) = () type bit = b:nat { b <= 1 } let lemma_offset_sum (a_agg:nat) (a0 a1 a2 a3 a4:nat64) (b_agg:nat) (b0 b1 b2 b3 b4:nat64) : Lemma (requires a_agg = pow2_five a0 a1 a2 a3 a4 /\ b_agg = pow2_five b0 b1 b2 b3 b4) (ensures a_agg + pow2_64 * b_agg = pow2_six a0 (a1 + b0) (a2 + b1) (a3 + b2) (a4 + b3) b4) = let lhs = a_agg + pow2_64 * b_agg in let rhs = pow2_six a0 (a1 + b0) (a2 + b1) (a3 + b2) (a4 + b3) b4 in assert_by_tactic (lhs == rhs) int_canon #push-options "--z3rlimit 60" let lemma_partial_sum (a0 a1 a2 a3 a4 b0 b1 b2 b3 b4 s1 s2 s3 s4 s5 c:nat64) : Lemma (requires (let s1', c1 = add_carry a1 b0 0 in let s2', c2 = add_carry a2 b1 c1 in let s3', c3 = add_carry a3 b2 c2 in let s4', c4 = add_carry a4 b3 c3 in let s5', c5 = add_carry 0 b4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ c == c5)) (ensures pow2_six a0 (a1 + b0) (a2 + b1) (a3 + b2) (a4 + b3) b4 = pow2_seven a0 s1 s2 s3 s4 s5 c) = () let lemma_partial_sum_a2b (a0 a1 a2 a3 a4 a5 b0 b1 b2 b3 b4 s1 s2 s3 s4 s5:nat64) : Lemma (requires (let s1', c1 = add_carry a2 b0 0 in let s2', c2 = add_carry a3 b1 c1 in let s3', c3 = add_carry a4 b2 c2 in let s4', c4 = add_carry a5 b3 c3 in let s5', c5 = add_carry 0 b4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ 0 == c5)) (ensures pow2_seven a0 a1 (a2 + b0) (a3 + b1) (a4 + b2) (a5 + b3) b4 = pow2_seven a0 a1 s1 s2 s3 s4 s5) = () let lemma_partial_sum_a3b ( a0 a1 a2 a3 a4 a5 a6 b0 b1 b2 b3 b4 s1 s2 s3 s4 s5:nat64) : Lemma (requires(let s1', c1 = add_carry a3 b0 0 in let s2', c2 = add_carry a4 b1 c1 in let s3', c3 = add_carry a5 b2 c2 in let s4', c4 = add_carry a6 b3 c3 in let s5', c5 = add_carry 0 b4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ 0 == c5)) (ensures pow2_eight a0 a1 a2 (a3 + b0) (a4 + b1) (a5 + b2) (a6 + b3) b4 = pow2_eight a0 a1 a2 s1 s2 s3 s4 s5) = () #pop-options let lemma_sum_a1b (a0 a1:nat64) (a0b:nat) (a0b_0 a0b_1 a0b_2 a0b_3 a0b_4:nat64) (a1b:nat) (a1b_0 a1b_1 a1b_2 a1b_3 a1b_4:nat64) (b:nat) (b0 b1 b2 b3:nat64) (s1 s2 s3 s4 s5 c:nat64) : Lemma (requires a0b = pow2_five a0b_0 a0b_1 a0b_2 a0b_3 a0b_4 /\ a1b = pow2_five a1b_0 a1b_1 a1b_2 a1b_3 a1b_4 /\ b = pow2_four b0 b1 b2 b3 /\ a0b = mul_nats a0 b /\ a1b = mul_nats a1 b /\ (let s1', c1 = add_carry a0b_1 a1b_0 0 in let s2', c2 = add_carry a0b_2 a1b_1 c1 in let s3', c3 = add_carry a0b_3 a1b_2 c2 in let s4', c4 = add_carry a0b_4 a1b_3 c3 in let s5', c5 = add_carry 0 a1b_4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ c5 == c)) (ensures (pow2_two a0 a1) * b == pow2_seven a0b_0 s1 s2 s3 s4 s5 c) = assert_by_tactic ( (pow2_two a0 a1) * b == pow2_two (mul_nats a0 b) (mul_nats a1 b)) int_canon; assert ( pow2_two (mul_nats a0 b) (mul_nats a1 b) == pow2_two a0b a1b); lemma_offset_sum a0b a0b_0 a0b_1 a0b_2 a0b_3 a0b_4 a1b a1b_0 a1b_1 a1b_2 a1b_3 a1b_4; assert ( pow2_two a0b a1b == pow2_six a0b_0 (a0b_1 + a1b_0) (a0b_2 + a1b_1) (a0b_3 + a1b_2) (a0b_4 + a1b_3) a1b_4); lemma_partial_sum a0b_0 a0b_1 a0b_2 a0b_3 a0b_4 a1b_0 a1b_1 a1b_2 a1b_3 a1b_4 s1 s2 s3 s4 s5 c; () #push-options "--z3rlimit 60" let lemma_sum_a2b (a0 a1 a2:nat64) (a0a1b:nat) (a0a1b_0 a0a1b_1 a0a1b_2 a0a1b_3 a0a1b_4 a0a1b_5:nat64) (a2b:nat) (a2b_0 a2b_1 a2b_2 a2b_3 a2b_4:nat64) (b:nat) (b0 b1 b2 b3:nat64) (s1 s2 s3 s4 s5:nat64) : Lemma (requires a0a1b = pow2_six a0a1b_0 a0a1b_1 a0a1b_2 a0a1b_3 a0a1b_4 a0a1b_5 /\ a2b = pow2_five a2b_0 a2b_1 a2b_2 a2b_3 a2b_4 /\ b = pow2_four b0 b1 b2 b3 /\ a0a1b = mul_nats (pow2_two a0 a1) b /\ a2b = mul_nats a2 b /\ (let s1', c1 = add_carry a0a1b_2 a2b_0 0 in let s2', c2 = add_carry a0a1b_3 a2b_1 c1 in let s3', c3 = add_carry a0a1b_4 a2b_2 c2 in let s4', c4 = add_carry a0a1b_5 a2b_3 c3 in let s5', c5 = add_carry 0 a2b_4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ c5 == 0)) (ensures (pow2_three a0 a1 a2) * b == pow2_seven a0a1b_0 a0a1b_1 s1 s2 s3 s4 s5) = assert_by_tactic ( (pow2_three a0 a1 a2) * b == mul_nats (pow2_two a0 a1) b + pow2_128 * (mul_nats a2 b)) int_canon; assert ( mul_nats (pow2_two a0 a1) b + pow2_128 * (mul_nats a2 b) == a0a1b + pow2_128 * a2b); assert_by_tactic ( a0a1b + pow2_128 * a2b == pow2_seven a0a1b_0 a0a1b_1 (a0a1b_2 + a2b_0) (a0a1b_3 + a2b_1) (a0a1b_4 + a2b_2) (a0a1b_5 + a2b_3) a2b_4) int_canon; lemma_partial_sum_a2b a0a1b_0 a0a1b_1 a0a1b_2 a0a1b_3 a0a1b_4 a0a1b_5 a2b_0 a2b_1 a2b_2 a2b_3 a2b_4 s1 s2 s3 s4 s5; () let lemma_sum_a3b (a0 a1 a2 a3:nat64) (a0a1a2b:nat) (a0a1a2b_0 a0a1a2b_1 a0a1a2b_2 a0a1a2b_3 a0a1a2b_4 a0a1a2b_5 a0a1a2b_6:nat64) (a3b:nat) (a3b_0 a3b_1 a3b_2 a3b_3 a3b_4:nat64) (b:nat) (b0 b1 b2 b3:nat64) (s1 s2 s3 s4 s5:nat64) : Lemma (requires a0a1a2b = pow2_seven a0a1a2b_0 a0a1a2b_1 a0a1a2b_2 a0a1a2b_3 a0a1a2b_4 a0a1a2b_5 a0a1a2b_6 /\ a3b = pow2_five a3b_0 a3b_1 a3b_2 a3b_3 a3b_4 /\ b = pow2_four b0 b1 b2 b3 /\ a0a1a2b = mul_nats (pow2_three a0 a1 a2) b /\ a3b = mul_nats a3 b /\ (let s1', c1 = add_carry a0a1a2b_3 a3b_0 0 in let s2', c2 = add_carry a0a1a2b_4 a3b_1 c1 in let s3', c3 = add_carry a0a1a2b_5 a3b_2 c2 in let s4', c4 = add_carry a0a1a2b_6 a3b_3 c3 in let s5', c5 = add_carry 0 a3b_4 c4 in s1 == s1' /\ s2 == s2' /\ s3 == s3' /\ s4 == s4' /\ s5 == s5' /\ c5 == 0)) (ensures (pow2_four a0 a1 a2 a3) * b == pow2_eight a0a1a2b_0 a0a1a2b_1 a0a1a2b_2 s1 s2 s3 s4 s5) = assert_by_tactic ( (pow2_four a0 a1 a2 a3) * b == mul_nats (pow2_three a0 a1 a2) b + pow2_192 * (mul_nats a3 b)) int_canon; assert ( mul_nats (pow2_three a0 a1 a2) b + pow2_192 * (mul_nats a3 b) == a0a1a2b + pow2_192 * a3b); assert_by_tactic ( a0a1a2b + pow2_192 * a3b == pow2_eight a0a1a2b_0 a0a1a2b_1 a0a1a2b_2 (a0a1a2b_3 + a3b_0) (a0a1a2b_4 + a3b_1) (a0a1a2b_5 + a3b_2) (a0a1a2b_6 + a3b_3) a3b_4) int_canon; lemma_partial_sum_a3b a0a1a2b_0 a0a1a2b_1 a0a1a2b_2 a0a1a2b_3 a0a1a2b_4 a0a1a2b_5 a0a1a2b_6 a3b_0 a3b_1 a3b_2 a3b_3 a3b_4 s1 s2 s3 s4 s5; () #pop-options let lemma_dbl_pow2_six (z0 z1 z2 z3 z4 z5:nat) : Lemma (2*pow2_six z0 z1 z2 z3 z4 z5 == pow2_six (2*z0) (2*z1) (2*z2) (2*z3) (2*z4) (2*z5)) = () let lemma_shift_pow2_eight (z0 z1 z2 z3 z4 z5 z6:nat) : Lemma (pow2_eight 0 z0 z1 z2 z3 z4 z5 z6 == pow2_64 * pow2_seven z0 z1 z2 z3 z4 z5 z6) = () #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from 'FStar.Pervasives Prims Vale.Def.Words_s Vale.Curve25519.Fast_defs'" val lemma_sqr (a:int) (a0 a1 a2 a3 r8 r9 r10 r11 r12 r13 rax rcx r8' r9' r10' r11' r12' r13' r14' d0 d1 d2 d3 d4 d5 d6 d7:nat64) (cf:bit) : Lemma (requires a = pow2_four a0 a1 a2 a3 /\ pow2_six r8 r9 r10 r11 r12 r13 == pow2_five (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3) (mul_nats a1 a3) (mul_nats a2 a3) /\ pow2_64 * rcx + rax == a1 * a2 /\ pow2_seven r8' r9' r10' r11' r12' r13' r14' == pow2_six (2*r8) (2*r9) (2*(r10+rax)) (2*(r11+rcx)) (2*r12) (2*r13) /\ pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14') (ensures a*a == pow2_eight d0 d1 d2 d3 d4 d5 d6 d7)
{ "checked_file": "/", "dependencies": [ "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Curve25519.Fast_lemmas_internal.fsti.checked", "Vale.Curve25519.Fast_defs.fst.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.Curve25519.FastMul_helpers.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519.Fast_lemmas_internal", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519.Fast_defs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519.Fast_defs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Vale.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> a0: Vale.Def.Types_s.nat64 -> a1: Vale.Def.Types_s.nat64 -> a2: Vale.Def.Types_s.nat64 -> a3: Vale.Def.Types_s.nat64 -> r8: Vale.Def.Types_s.nat64 -> r9: Vale.Def.Types_s.nat64 -> r10: Vale.Def.Types_s.nat64 -> r11: Vale.Def.Types_s.nat64 -> r12: Vale.Def.Types_s.nat64 -> r13: Vale.Def.Types_s.nat64 -> rax: Vale.Def.Types_s.nat64 -> rcx: Vale.Def.Types_s.nat64 -> r8': Vale.Def.Types_s.nat64 -> r9': Vale.Def.Types_s.nat64 -> r10': Vale.Def.Types_s.nat64 -> r11': Vale.Def.Types_s.nat64 -> r12': Vale.Def.Types_s.nat64 -> r13': Vale.Def.Types_s.nat64 -> r14': Vale.Def.Types_s.nat64 -> d0: Vale.Def.Types_s.nat64 -> d1: Vale.Def.Types_s.nat64 -> d2: Vale.Def.Types_s.nat64 -> d3: Vale.Def.Types_s.nat64 -> d4: Vale.Def.Types_s.nat64 -> d5: Vale.Def.Types_s.nat64 -> d6: Vale.Def.Types_s.nat64 -> d7: Vale.Def.Types_s.nat64 -> cf: Vale.Curve25519.FastMul_helpers.bit -> FStar.Pervasives.Lemma (requires a = Vale.Curve25519.Fast_defs.pow2_four a0 a1 a2 a3 /\ Vale.Curve25519.Fast_defs.pow2_six r8 r9 r10 r11 r12 r13 == Vale.Curve25519.Fast_defs.pow2_five (Vale.Curve25519.Fast_defs.mul_nats a0 a1) (Vale.Curve25519.Fast_defs.mul_nats a0 a2) (Vale.Curve25519.Fast_defs.mul_nats a0 a3) (Vale.Curve25519.Fast_defs.mul_nats a1 a3) (Vale.Curve25519.Fast_defs.mul_nats a2 a3) /\ Vale.Def.Words_s.pow2_64 * rcx + rax == a1 * a2 /\ Vale.Curve25519.Fast_defs.pow2_seven r8' r9' r10' r11' r12' r13' r14' == Vale.Curve25519.Fast_defs.pow2_six (2 * r8) (2 * r9) (2 * (r10 + rax)) (2 * (r11 + rcx)) (2 * r12) (2 * r13) /\ Vale.Curve25519.Fast_defs.pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == Vale.Curve25519.Fast_defs.pow2_eight (Vale.Curve25519.Fast_defs.mul_nats a0 a0) r8' (Vale.Curve25519.Fast_defs.mul_nats a1 a1 + r9') r10' (Vale.Curve25519.Fast_defs.mul_nats a2 a2 + r11') r12' (Vale.Curve25519.Fast_defs.mul_nats a3 a3 + r13') r14') (ensures a * a == Vale.Curve25519.Fast_defs.pow2_eight d0 d1 d2 d3 d4 d5 d6 d7)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.Def.Types_s.nat64", "Vale.Curve25519.FastMul_helpers.bit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "Vale.Curve25519.Fast_defs.pow2_nine", "Vale.Curve25519.FastMul_helpers.int_canon", "Prims.unit", "Vale.Curve25519.Fast_defs.pow2_eight", "Prims._assert", "FStar.Mul.op_Star", "FStar.Calc.calc_finish", "Vale.Curve25519.Fast_defs.mul_nats", "Prims.op_Addition", "Vale.Curve25519.Fast_defs.pow2_seven", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Tactics.CanonCommSemiring.semiring_reflect", "FStar.Tactics.CanonCommSemiring.int_cr", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "FStar.Pervasives.Native.tuple2", "Prims.nat", "FStar.Pervasives.Native.snd", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Stubs.Reflection.V2.Data.var", "FStar.Tactics.CanonCommSemiring.Pplus", "FStar.Tactics.CanonCommSemiring.Pmult", "FStar.Tactics.CanonCommSemiring.Pvar", "FStar.Tactics.CanonCommSemiring.Pconst", "Prims.op_Multiply", "Prims.squash", "Vale.Def.Words_s.pow2_64", "Vale.Curve25519.Fast_defs.pow2_six", "Vale.Curve25519.FastMul_helpers.lemma_shift_pow2_eight", "Vale.Curve25519.FastMul_helpers.lemma_dbl_pow2_six", "Vale.Curve25519.Fast_defs.pow2_four", "FStar.Tactics.V1.Derived.qed", "FStar.Tactics.V1.Derived.trefl", "Prims.l_imp", "Prims.op_Equality", "Vale.Curve25519.Fast_defs.pow2_512", "Prims.op_LessThan", "Vale.Curve25519.Fast_defs.pow2_256", "Vale.Curve25519.FastMul_helpers.lemma_mul_pow2_bound", "FStar.Math.Lemmas.pow2_plus", "FStar.Pervasives.assert_norm", "Prims.pow2" ]
[]
false
false
true
false
false
let lemma_sqr a a0 a1 a2 a3 r8 r9 r10 r11 r12 r13 rax rcx r8' r9' r10' r11' r12' r13' r14' d0 d1 d2 d3 d4 d5 d6 d7 cf =
assert (a < pow2_256); assert_norm (pow2_256 == pow2 256); pow2_plus 256 256; lemma_mul_pow2_bound 256 a a; assert (a * a < pow2_256 * pow2_256); assert (cf = 1 ==> pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf >= pow2_512); assert_by_tactic ((pow2_four a0 a1 a2 a3) * (pow2_four a0 a1 a2 a3) == pow2_seven (mul_nats a0 a0) (2 * (mul_nats a0 a1)) (2 * (mul_nats a0 a2) + (mul_nats a1 a1)) (2 * ((mul_nats a0 a3) + (mul_nats a1 a2))) (2 * (mul_nats a1 a3) + (mul_nats a2 a2)) (2 * (mul_nats a2 a3)) (mul_nats a3 a3)) (fun _ -> int_canon (); trefl (); qed ()); let lhs:int = pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14' in let squares = pow2_eight (mul_nats a0 a0) 0 (mul_nats a1 a1) 0 (mul_nats a2 a2) 0 (mul_nats a3 a3) 0 in let regs = pow2_eight 0 r8' r9' r10' r11' r12' r13' r14' in let rhs:int = squares + regs in assert (2 * (mul_nats a0 a3 + a1 * a2) >= 0); calc (eq2 #int) { pow2_eight (mul_nats a0 a0) r8' ((mul_nats a1 a1) + r9') r10' ((mul_nats a2 a2) + r11') r12' ((mul_nats a3 a3) + r13') r14'; (eq2 #int) { FStar.Tactics.Effect.synth_by_tactic (fun _ -> (int_canon ())) } pow2_eight (mul_nats a0 a0) 0 (mul_nats a1 a1) 0 (mul_nats a2 a2) 0 (mul_nats a3 a3) 0 + pow2_eight 0 r8' r9' r10' r11' r12' r13' r14'; (eq2 #int) { calc (eq2 #int) { pow2_eight 0 r8' r9' r10' r11' r12' r13' r14'; (eq2 #int) { lemma_shift_pow2_eight r8' r9' r10' r11' r12' r13' r14' } pow2_64 * pow2_six (2 * r8) (2 * r9) (2 * (r10 + rax)) (2 * (r11 + rcx)) (2 * r12) (2 * r13); (eq2 #int) { calc (eq2 #int) { pow2_six (2 * r8) (2 * r9) (2 * (r10 + rax)) (2 * (r11 + rcx)) (2 * r12) (2 * r13); (eq2 #int) { lemma_dbl_pow2_six r8 r9 (r10 + rax) (r11 + rcx) r12 r13 } 2 * pow2_six r8 r9 (r10 + rax) (r11 + rcx) r12 r13; (eq2 #int) { () } 2 * pow2_six (mul_nats a0 a1) (mul_nats a0 a2) (mul_nats a0 a3 + a1 * a2) (mul_nats a1 a3) (mul_nats a2 a3) 0; (eq2 #int) { () } pow2_six (2 * (mul_nats a0 a1)) (2 * (mul_nats a0 a2)) (2 * (mul_nats a0 a3 + a1 * a2)) (2 * (mul_nats a1 a3)) (2 * (mul_nats a2 a3)) 0; } } pow2_64 * pow2_six (2 * (mul_nats a0 a1)) (2 * (mul_nats a0 a2)) (2 * (mul_nats a0 a3 + a1 * a2)) (2 * (mul_nats a1 a3)) (2 * (mul_nats a2 a3)) 0; (eq2 #int) { () } pow2_seven 0 (2 * (mul_nats a0 a1)) (2 * (mul_nats a0 a2)) (2 * (mul_nats a0 a3 + a1 * a2)) (2 * (mul_nats a1 a3)) (2 * (mul_nats a2 a3)) 0; } } pow2_eight (mul_nats a0 a0) (2 * (mul_nats a0 a1)) ((2 * (mul_nats a0 a2)) + mul_nats a1 a1) (2 * (mul_nats a0 a3 + a1 * a2)) ((2 * (mul_nats a1 a3)) + mul_nats a2 a2) (2 * (mul_nats a2 a3)) (mul_nats a3 a3) 0; (eq2 #int) { () } pow2_seven (mul_nats a0 a0) (2 * (mul_nats a0 a1)) ((2 * (mul_nats a0 a2)) + mul_nats a1 a1) (2 * (mul_nats a0 a3 + a1 * a2)) ((2 * (mul_nats a1 a3)) + mul_nats a2 a2) (2 * (mul_nats a2 a3)) (mul_nats a3 a3); }; assert (pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == a * a); let ultimate_rhs:int = pow2_eight d0 d1 d2 d3 d4 d5 d6 d7 in assert_by_tactic (pow2_nine d0 d1 d2 d3 d4 d5 d6 d7 cf == ultimate_rhs) int_canon
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_fmul_gmul
val lemma_fmul_gmul (f: G.field) (a b: G.felem f) : Lemma (fmul f a b == gmul f a b)
val lemma_fmul_gmul (f: G.field) (a b: G.felem f) : Lemma (fmul f a b == gmul f a b)
let lemma_fmul_gmul (f:G.field) (a b:G.felem f) : Lemma (fmul f a b == gmul f a b) = let pred (n:nat) (pab:(fmul_t f)) : Type0 = gmul_rec f a b n == pab in let _ = Lib.LoopCombinators.repeati_inductive' (I.bits f.G.t - 1) pred (fmul_iter f) (G.zero #f, a, b) in ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 543, "start_col": 0, "start_line": 538 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); () #reset-options "--z3rlimit 20" let rec lemma_smul_gmul_rec (f:G.field) (e1 e2:G.felem f) (n:nat) : Lemma ( let (p, a, b) = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) = let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then ( lemma_smul_gmul_rec f e1 e2 (n - 1); let (sp, sa, sb) = smul_rec a b m (n - 1) in let (gp, ga, gb) = gmul_rec f e1 e2 (n - 1) in //assert (to_poly gp == sp); //assert (to_poly ga == sa); //assert (to_poly gb == sb); let sp' = sp +. (if sb.[0] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in // mod_bit1 is equivalent to mod in this case let sb' = shift sb (-1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[k - 1] then m_lo else zero in let ssa' = ssa +. ssa_add in //assert (sa' == ssa'); let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[0] then lemma_equal (sb &. one) one; //assert (sb.[0] <==> I.v (I.logand gb (G.one #f)) = I.v (G.one #f)); lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); //assert (to_poly gp' == sp'); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; //assert (to_poly f.G.irred == m_lo); lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); //assert (to_poly carry_irred == ssa_add); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); //assert (to_poly ga_shift == ssa); //assert (to_poly ga' == ssa'); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); //assert (to_poly gb' == sb'); () ) let lemma_smul_fmul (f:G.field) (e1 e2:G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t)) = let G.GF t irred = f in let n = I.bits t in lemma_smul_gmul_rec f e1 e2 n
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.fmul f a b == Vale.Math.Poly2.Galois.gmul f a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Vale.Math.Poly2.Galois.fmul_t", "Lib.LoopCombinators.repeati_inductive'", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t", "Vale.Math.Poly2.Galois.fmul_iter", "FStar.Pervasives.Native.Mktuple3", "Spec.GaloisField.zero", "Prims.nat", "Prims.eq2", "Vale.Math.Poly2.Galois.gmul_rec", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Galois.fmul", "Vale.Math.Poly2.Galois.gmul", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_fmul_gmul (f: G.field) (a b: G.felem f) : Lemma (fmul f a b == gmul f a b) =
let pred (n: nat) (pab: (fmul_t f)) : Type0 = gmul_rec f a b n == pab in let _ = Lib.LoopCombinators.repeati_inductive' (I.bits f.G.t - 1) pred (fmul_iter f) (G.zero #f, a, b) in ()
false
GTWP.fst
GTWP.m
val m (a: Type u#aa) (i: idx) (w: wp a) : Type u#aa
val m (a: Type u#aa) (i: idx) (w: wp a) : Type u#aa
let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 28, "start_col": 0, "start_line": 24 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> i: GTWP.idx -> w: GTWP.wp a -> Type
Prims.Tot
[ "total" ]
[]
[ "GTWP.idx", "GTWP.wp", "Prims.unit", "FStar.Universe.raise_t" ]
[]
false
false
false
true
true
let m (a: Type u#aa) (i: idx) (w: wp a) : Type u#aa =
match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w)
false
GTWP.fst
GTWP.bind_wp
val bind_wp (#a #b: _) (wc: wp a) (wf: (a -> wp b)) : wp b
val bind_wp (#a #b: _) (wc: wp a) (wf: (a -> wp b)) : wp b
let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p))
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 22, "start_col": 0, "start_line": 20 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wc: GTWP.wp a -> wf: (_: a -> GTWP.wp b) -> GTWP.wp b
Prims.Tot
[ "total" ]
[]
[ "GTWP.wp", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.l_True", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall" ]
[]
false
false
false
true
false
let bind_wp #a #b (wc: wp a) (wf: (a -> wp b)) : wp b =
elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p))
false
GTWP.fst
GTWP.return
val return (a: Type) (x: a) (i: idx) : m a i (return_wp x)
val return (a: Type) (x: a) (i: idx) : m a i (return_wp x)
let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 41, "start_col": 0, "start_line": 37 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> i: GTWP.idx -> GTWP.m a i (GTWP.return_wp x)
Prims.Tot
[ "total" ]
[]
[ "GTWP.idx", "GTWP.t_return", "GTWP.g_return", "GTWP.coerce", "GTWP.m", "GTWP.D", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre", "GTWP.return_wp", "GTWP.d_return" ]
[]
false
false
false
false
false
let return (a: Type) (x: a) (i: idx) : m a i (return_wp x) =
match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x)
false
GTWP.fst
GTWP.g_return
val g_return (#a: _) (x: a) : m a G (as_pure_wp (fun p -> p x))
val g_return (#a: _) (x: a) : m a G (as_pure_wp (fun p -> p x))
let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 31, "start_col": 0, "start_line": 31 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> GTWP.m a GTWP.G (FStar.Monotonic.Pure.as_pure_wp (fun p -> p x))
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "GTWP.m", "GTWP.G", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre" ]
[]
false
false
false
false
false
let g_return #a (x: a) : m a G (as_pure_wp (fun p -> p x)) =
(fun () -> x)
false
Steel.Reference.fsti
Steel.Reference.ghost_gather
val ghost_gather (#a: Type0) (#uses: _) (#p: perm) (r: ghost_ref a) : SteelGhost unit uses ((ghost_vptrp r (half_perm p)) `star` (ghost_vptrp r (half_perm p))) (fun _ -> ghost_vptrp r p) (fun _ -> True) (fun h _ h' -> h' (ghost_vptrp r p) == h (ghost_vptrp r (half_perm p)))
val ghost_gather (#a: Type0) (#uses: _) (#p: perm) (r: ghost_ref a) : SteelGhost unit uses ((ghost_vptrp r (half_perm p)) `star` (ghost_vptrp r (half_perm p))) (fun _ -> ghost_vptrp r p) (fun _ -> True) (fun h _ h' -> h' (ghost_vptrp r p) == h (ghost_vptrp r (half_perm p)))
let ghost_gather (#a: Type0) (#uses: _) (#p: perm) (r: ghost_ref a) : SteelGhost unit uses (ghost_vptrp r (half_perm p) `star` ghost_vptrp r (half_perm p)) (fun _ -> ghost_vptrp r p) (fun _ -> True) (fun h _ h' -> h' (ghost_vptrp r p) == h (ghost_vptrp r (half_perm p)) ) = let _ = ghost_gather_gen r _ _ in change_equal_slprop (ghost_vptrp r _) (ghost_vptrp r p)
{ "file_name": "lib/steel/Steel.Reference.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 561, "start_col": 0, "start_line": 550 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Reference open FStar.Ghost open Steel.FractionalPermission open Steel.Memory open Steel.Effect.Atomic open Steel.Effect module U32 = FStar.UInt32 module Mem = Steel.Memory /// The main user-facing Steel library. /// This library provides functions to operate on references to values in universe 0, such as uints. /// This library provides two versions, which can interoperate with each other. /// The first one uses the standard separation logic pts_to predicate, and has a non-informative selector /// The second one has a selector which returns the contents of the reference in memory, enabling /// to better separate reasoning about memory safety and functional correctness when handling references. /// An abstract datatype for references val ref ([@@@unused] a:Type0) : Type0 /// The null pointer [@@ noextract_to "krml"] val null (#a:Type0) : ref a /// Checking whether a pointer is null can be done in a decidable way [@@ noextract_to "krml"] val is_null (#a:Type0) (r:ref a) : (b:bool{b <==> r == null}) (** First version of references: Non-informative selector and standard pts_to predicate. All functions names here are postfixed with _pt (for points_to)**) /// The standard points to separation logic assertion, expressing that /// reference [r] is valid in memory, stores value [v], and that we have /// permission [p] on it. val pts_to_sl (#a:Type0) (r:ref a) (p:perm) (v:a) : slprop u#1 /// Lifting the standard points to predicate to vprop, with a non-informative selector. /// The permission [p] and the value [v] are annotated with the smt_fallback attribute, /// enabling SMT rewriting on them during frame inference [@@ __steel_reduce__] let pts_to (#a:Type0) (r:ref a) ([@@@smt_fallback] p:perm) ([@@@ smt_fallback] v:a) = to_vprop (pts_to_sl r p v) /// If two pts_to predicates on the same reference [r] are valid in the memory [m], /// then the two values [v0] and [v1] are identical val pts_to_ref_injective (#a: Type u#0) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) /// A valid pts_to predicate implies that the pointer is not the null pointer val pts_to_not_null (#a:Type u#0) (x:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl x p v) m) (ensures x =!= null) /// Exposing the is_witness_invariant from Steel.Memory for references with fractional permissions val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) /// A stateful version of the pts_to_ref_injective lemma above val pts_to_injective_eq (#a: Type) (#opened:inames) (#p0 #p1:perm) (#v0 #v1: erased a) (r: ref a) : SteelGhost unit opened (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1) /// A permission is always no greater than one val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a) : SteelGhost unit u (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm) /// Allocates a reference with value [x]. We have full permission on the newly /// allocated reference. val alloc_pt (#a:Type) (x:a) : Steel (ref a) emp (fun r -> pts_to r full_perm x) (requires fun _ -> True) (ensures fun _ r _ -> not (is_null r)) /// Reads the value in reference [r], as long as it initially is valid val read_pt (#a:Type) (#p:perm) (#v:erased a) (r:ref a) : Steel a (pts_to r p v) (fun x -> pts_to r p x) (requires fun _ -> True) (ensures fun _ x _ -> x == Ghost.reveal v) /// A variant of read, useful when an existentially quantified predicate /// depends on the value stored in the reference val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) /// Writes value [x] in the reference [r], as long as we have full ownership of [r] val write_pt (#a:Type0) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) /// Frees reference [r], as long as we have full ownership of [r] val free_pt (#a:Type0) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) /// Splits the permission on reference [r] into two. /// This function is computationally irrelevant (it has effect SteelGhost) val share_gen_pt (#a:Type0) (#uses:_) (#p:perm) (#v: a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) val share_pt (#a:Type0) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) /// Combines permissions on reference [r]. /// This function is computationally irrelevant (it has effect SteelGhost) val gather_pt (#a:Type0) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) : SteelGhostT (_:unit{v0 == v1}) uses (pts_to r p0 v0 `star` pts_to r p1 v1) (fun _ -> pts_to r (sum_perm p0 p1) v0) /// Atomic operations, read, write, and cas /// /// These are not polymorphic and are allowed only for small types (e.g. word-sized) /// For now, exporting only for U32 val atomic_read_pt_u32 (#opened:_) (#p:perm) (#v:erased U32.t) (r:ref U32.t) : SteelAtomic U32.t opened (pts_to r p v) (fun x -> pts_to r p x) (requires fun _ -> True) (ensures fun _ x _ -> x == Ghost.reveal v) val atomic_write_pt_u32 (#opened:_) (#v:erased U32.t) (r:ref U32.t) (x:U32.t) : SteelAtomicT unit opened (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) val cas_pt_u32 (#uses:inames) (r:ref U32.t) (v:Ghost.erased U32.t) (v_old:U32.t) (v_new:U32.t) : SteelAtomicT (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to r full_perm v) (fun b -> if b then pts_to r full_perm v_new else pts_to r full_perm v) val cas_pt_bool (#uses:inames) (r:ref bool) (v:Ghost.erased bool) (v_old:bool) (v_new:bool) : SteelAtomicT (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to r full_perm v) (fun b -> if b then pts_to r full_perm v_new else pts_to r full_perm v) (** Second version of references: The memory contents are available inside the selector, instead of as an index of the predicate **) /// An abstract separation logic predicate stating that reference [r] is valid in memory. val ptrp (#a:Type0) (r:ref a) ([@@@smt_fallback] p: perm) : slprop u#1 [@@ __steel_reduce__; __reduce__] unfold let ptr (#a:Type0) (r:ref a) : slprop u#1 = ptrp r full_perm /// A selector for references, returning the value of type [a] stored in memory val ptrp_sel (#a:Type0) (r:ref a) (p: perm) : selector a (ptrp r p) [@@ __steel_reduce__; __reduce__] unfold let ptr_sel (#a:Type0) (r:ref a) : selector a (ptr r) = ptrp_sel r full_perm /// Some lemmas to interoperate between the two versions of references val ptrp_sel_interp (#a:Type0) (r:ref a) (p: perm) (m:mem) : Lemma (requires interp (ptrp r p) m) (ensures interp (pts_to_sl r p (ptrp_sel r p m)) m) let ptr_sel_interp (#a:Type0) (r:ref a) (m:mem) : Lemma (requires interp (ptr r) m) (ensures interp (pts_to_sl r full_perm (ptr_sel r m)) m) = ptrp_sel_interp r full_perm m val intro_ptrp_interp (#a:Type0) (r:ref a) (p: perm) (v:erased a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures interp (ptrp r p) m) let intro_ptr_interp (#a:Type0) (r:ref a) (v:erased a) (m:mem) : Lemma (requires interp (pts_to_sl r full_perm v) m) (ensures interp (ptr r) m) = intro_ptrp_interp r full_perm v m /// Combining the separation logic predicate and selector into a vprop [@@ __steel_reduce__] let vptr' #a r p : vprop' = {hp = ptrp r p; t = a; sel = ptrp_sel r p} [@@ __steel_reduce__] unfold let vptrp (#a: Type) (r: ref a) ([@@@smt_fallback] p: perm) = VUnit (vptr' r p) [@@ __steel_reduce__; __reduce__] unfold let vptr r = vptrp r full_perm /// A wrapper to access a reference selector more easily. /// Ensuring that the corresponding ptr vprop is in the context is done by /// calling a variant of the framing tactic, as defined in Steel.Effect.Common [@@ __steel_reduce__] let sel (#a:Type) (#p:vprop) (r:ref a) (h:rmem p{FStar.Tactics.with_tactic selector_tactic (can_be_split p (vptr r) /\ True)}) = h (vptr r) /// Moving from indexed pts_to assertions to selector-based vprops and back val intro_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) (v:erased a) : SteelGhost unit opened (pts_to r p v) (fun _ -> vptrp r p) (requires fun _ -> True) (ensures fun _ _ h1 -> h1 (vptrp r p) == reveal v) val elim_vptr (#a:Type) (#opened:inames) (r:ref a) (p: perm) : SteelGhost (erased a) opened (vptrp r p) (fun v -> pts_to r p v) (requires fun _ -> True) (ensures fun h0 v _ -> reveal v == h0 (vptrp r p)) /// Allocates a reference with value [x]. val malloc (#a:Type0) (x:a) : Steel (ref a) emp (fun r -> vptr r) (requires fun _ -> True) (ensures fun _ r h1 -> sel r h1 == x /\ not (is_null r)) /// Frees a reference [r] val free (#a:Type0) (r:ref a) : Steel unit (vptr r) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> True) /// Reads the current value of reference [r] val readp (#a:Type0) (r:ref a) (p: perm) : Steel a (vptrp r p) (fun _ -> vptrp r p) (requires fun _ -> True) (ensures fun h0 x h1 -> h0 (vptrp r p) == h1 (vptrp r p) /\ x == h1 (vptrp r p)) let read (#a:Type0) (r:ref a) : Steel a (vptr r) (fun _ -> vptr r) (requires fun _ -> True) (ensures fun h0 x h1 -> sel r h0 == sel r h1 /\ x == sel r h1) = readp r full_perm /// Writes value [x] in reference [r] val write (#a:Type0) (r:ref a) (x:a) : Steel unit (vptr r) (fun _ -> vptr r) (requires fun _ -> True) (ensures fun _ _ h1 -> x == sel r h1) val share (#a:Type0) (#uses:_) (#p: perm) (r:ref a) : SteelGhost unit uses (vptrp r p) (fun _ -> vptrp r (half_perm p) `star` vptrp r (half_perm p)) (fun _ -> True) (fun h _ h' -> h' (vptrp r (half_perm p)) == h (vptrp r p) ) val gather_gen (#a:Type0) (#uses:_) (r:ref a) (p0:perm) (p1:perm) : SteelGhost perm uses (vptrp r p0 `star` vptrp r p1) (fun res -> vptrp r res) (fun _ -> True) (fun h res h' -> res == sum_perm p0 p1 /\ h' (vptrp r res) == h (vptrp r p0) /\ h' (vptrp r res) == h (vptrp r p1) ) val gather (#a: Type0) (#uses: _) (#p: perm) (r: ref a) : SteelGhost unit uses (vptrp r (half_perm p) `star` vptrp r (half_perm p)) (fun _ -> vptrp r p) (fun _ -> True) (fun h _ h' -> h' (vptrp r p) == h (vptrp r (half_perm p)) ) /// A stateful lemma variant of the pts_to_not_null lemma above. /// This stateful function is computationally irrelevant and does not modify memory val vptrp_not_null (#opened: _) (#a: Type) (r: ref a) (p: perm) : SteelGhost unit opened (vptrp r p) (fun _ -> vptrp r p) (fun _ -> True) (fun h0 _ h1 -> h0 (vptrp r p) == h1 (vptrp r p) /\ is_null r == false ) let vptr_not_null (#opened: _) (#a: Type) (r: ref a) : SteelGhost unit opened (vptr r) (fun _ -> vptr r) (fun _ -> True) (fun h0 _ h1 -> sel r h0 == sel r h1 /\ is_null r == false ) = vptrp_not_null r full_perm (*** Ghost references ***) /// We also define a ghost variant of references, useful to do proofs relying on a ghost state /// Ghost references are marked as erasable, ensuring that they are computationally irrelevant, /// and only used in computationally irrelevant contexts. /// The functions below are variants of the reference functions defined above, /// but operating on ghost references, and with the computationally irrelevant SteelGhost effect [@@ erasable] val ghost_ref (a:Type u#0) : Type u#0 val dummy_ghost_ref (a: Type) : Tot (ghost_ref a) (* Textbook separation logic version of ghost references *) val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (v:a) : slprop u#1 [@@ __steel_reduce__] let ghost_pts_to (#a:Type0) (r:ghost_ref a) ([@@@smt_fallback] p:perm) ([@@@ smt_fallback] v:a) : vprop = to_vprop (ghost_pts_to_sl r p v) val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) val ghost_alloc_pt (#a:Type) (#u:_) (x:erased a) : SteelGhostT (ghost_ref a) u emp (fun r -> ghost_pts_to r full_perm x) val ghost_free_pt (#a:Type0) (#u:_) (#v:erased a) (r:ghost_ref a) : SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> emp) val ghost_share_gen_pt (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) (p1 p2: perm) : SteelGhost unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r p1 x `star` ghost_pts_to r p2 x) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) val ghost_share_pt (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) : SteelGhostT unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r (half_perm p) x `star` ghost_pts_to r (half_perm p) x) val ghost_gather_pt (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r (sum_perm p0 p1) x0) (requires fun _ -> true) (ensures fun _ _ _ -> x0 == x1) val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a) : SteelGhost unit u (ghost_pts_to r p v0 `star` ghost_pts_to r q v1) (fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1) /// A permission is always no greater than one val ghost_pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ghost_ref a) : SteelGhost unit u (ghost_pts_to r p v) (fun _ -> ghost_pts_to r p v) (fun _ -> True) (fun _ _ _ -> p `lesser_equal_perm` full_perm) val ghost_read_pt (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ghost_ref a) : SteelGhost (erased a) u (ghost_pts_to r p v) (fun x -> ghost_pts_to r p x) (requires fun _ -> True) (ensures fun _ x _ -> x == v) val ghost_write_pt (#a:Type) (#u:_) (#v:erased a) (r:ghost_ref a) (x:erased a) : SteelGhostT unit u (ghost_pts_to r full_perm v) (fun _ -> ghost_pts_to r full_perm x) (* Selector version of ghost references *) val ghost_ptrp (#a: Type0) (r: ghost_ref a) ([@@@smt_fallback] p: perm) : slprop u#1 [@@ __steel_reduce__; __reduce__] unfold let ghost_ptr (#a: Type0) (r: ghost_ref a) : slprop u#1 = ghost_ptrp r full_perm val ghost_ptrp_sel (#a:Type0) (r:ghost_ref a) (p: perm) : selector a (ghost_ptrp r p) [@@ __steel_reduce__; __reduce__] let ghost_ptr_sel (#a:Type0) (r:ghost_ref a) : selector a (ghost_ptr r) = ghost_ptrp_sel r full_perm val ghost_ptrp_sel_interp (#a:Type0) (r:ghost_ref a) (p: perm) (m:mem) : Lemma (requires interp (ghost_ptrp r p) m) (ensures interp (ghost_pts_to_sl r p (ghost_ptrp_sel r p m)) m) let ghost_ptr_sel_interp (#a:Type0) (r:ghost_ref a) (m:mem) : Lemma (requires interp (ghost_ptr r) m) (ensures interp (ghost_pts_to_sl r full_perm (ghost_ptr_sel r m)) m) = ghost_ptrp_sel_interp r full_perm m [@@ __steel_reduce__] let ghost_vptr' #a r p : vprop' = {hp = ghost_ptrp r p; t = a; sel = ghost_ptrp_sel r p} [@@ __steel_reduce__] unfold let ghost_vptrp (#a: Type) (r: ghost_ref a) ([@@@smt_fallback] p: perm) = VUnit (ghost_vptr' r p) [@@ __steel_reduce__; __reduce__] unfold let ghost_vptr r = ghost_vptrp r full_perm [@@ __steel_reduce__] let ghost_sel (#a:Type) (#p:vprop) (r:ghost_ref a) (h:rmem p{FStar.Tactics.with_tactic selector_tactic (can_be_split p (ghost_vptr r) /\ True)}) = h (ghost_vptr r) val ghost_alloc (#a:Type0) (#opened:inames) (x:Ghost.erased a) : SteelGhost (ghost_ref a) opened emp (fun r -> ghost_vptr r) (requires fun _ -> True) (ensures fun _ r h1 -> ghost_sel r h1 == Ghost.reveal x) val ghost_free (#a:Type0) (#opened:inames) (r:ghost_ref a) : SteelGhost unit opened (ghost_vptr r) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> True) val ghost_readp (#a:Type0) (#opened:inames) (r:ghost_ref a) (p: perm) : SteelGhost (Ghost.erased a) opened (ghost_vptrp r p) (fun _ -> ghost_vptrp r p) (requires fun _ -> True) (ensures fun h0 x h1 -> h0 (ghost_vptrp r p) == h1 (ghost_vptrp r p) /\ Ghost.reveal x == h1 (ghost_vptrp r p)) let ghost_read (#a:Type0) (#opened:inames) (r:ghost_ref a) : SteelGhost (Ghost.erased a) opened (ghost_vptr r) (fun _ -> ghost_vptr r) (requires fun _ -> True) (ensures fun h0 x h1 -> h0 (ghost_vptr r) == h1 (ghost_vptr r) /\ Ghost.reveal x == h1 (ghost_vptr r)) = ghost_readp r full_perm val ghost_write (#a:Type0) (#opened:inames) (r:ghost_ref a) (x:Ghost.erased a) : SteelGhost unit opened (ghost_vptr r) (fun _ -> ghost_vptr r) (requires fun _ -> True) (ensures fun _ _ h1 -> Ghost.reveal x == h1 (ghost_vptr r)) val ghost_share (#a:Type0) (#uses:_) (#p: perm) (r:ghost_ref a) : SteelGhost unit uses (ghost_vptrp r p) (fun _ -> ghost_vptrp r (half_perm p) `star` ghost_vptrp r (half_perm p)) (fun _ -> True) (fun h res h' -> h' (ghost_vptrp r (half_perm p)) == h (ghost_vptrp r p) ) val ghost_gather_gen (#a:Type0) (#uses:_) (r:ghost_ref a) (p0:perm) (p1:perm) : SteelGhost perm uses (ghost_vptrp r p0 `star` ghost_vptrp r p1) (fun res -> ghost_vptrp r res) (fun _ -> True) (fun h res h' -> res == sum_perm p0 p1 /\ h' (ghost_vptrp r res) == h (ghost_vptrp r p0) /\ h' (ghost_vptrp r res) == h (ghost_vptrp r p1) )
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Reference.fsti" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Reference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.Reference.ghost_ref", "Steel.Effect.Atomic.change_equal_slprop", "Steel.Reference.ghost_vptrp", "Prims.unit", "Steel.Reference.ghost_gather_gen", "Steel.FractionalPermission.half_perm", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True", "Prims.eq2", "Steel.Effect.Common.normal", "Steel.Effect.Common.t_of" ]
[]
false
true
false
false
false
let ghost_gather (#a: Type0) (#uses: _) (#p: perm) (r: ghost_ref a) : SteelGhost unit uses ((ghost_vptrp r (half_perm p)) `star` (ghost_vptrp r (half_perm p))) (fun _ -> ghost_vptrp r p) (fun _ -> True) (fun h _ h' -> h' (ghost_vptrp r p) == h (ghost_vptrp r (half_perm p))) =
let _ = ghost_gather_gen r _ _ in change_equal_slprop (ghost_vptrp r _) (ghost_vptrp r p)
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_smul_fmul
val lemma_smul_fmul (f: G.field) (e1 e2: G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t))
val lemma_smul_fmul (f: G.field) (e1 e2: G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t))
let lemma_smul_fmul (f:G.field) (e1 e2:G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t)) = let G.GF t irred = f in let n = I.bits t in lemma_smul_gmul_rec f e1 e2 n
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 536, "start_col": 0, "start_line": 531 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); () #reset-options "--z3rlimit 20" let rec lemma_smul_gmul_rec (f:G.field) (e1 e2:G.felem f) (n:nat) : Lemma ( let (p, a, b) = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) = let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then ( lemma_smul_gmul_rec f e1 e2 (n - 1); let (sp, sa, sb) = smul_rec a b m (n - 1) in let (gp, ga, gb) = gmul_rec f e1 e2 (n - 1) in //assert (to_poly gp == sp); //assert (to_poly ga == sa); //assert (to_poly gb == sb); let sp' = sp +. (if sb.[0] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in // mod_bit1 is equivalent to mod in this case let sb' = shift sb (-1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[k - 1] then m_lo else zero in let ssa' = ssa +. ssa_add in //assert (sa' == ssa'); let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[0] then lemma_equal (sb &. one) one; //assert (sb.[0] <==> I.v (I.logand gb (G.one #f)) = I.v (G.one #f)); lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); //assert (to_poly gp' == sp'); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; //assert (to_poly f.G.irred == m_lo); lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); //assert (to_poly carry_irred == ssa_add); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); //assert (to_poly ga_shift == ssa); //assert (to_poly ga' == ssa'); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); //assert (to_poly gb' == sb'); () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> e1: Spec.GaloisField.felem f -> e2: Spec.GaloisField.felem f -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Galois.to_poly (Vale.Math.Poly2.Galois.gmul f e1 e2) == Vale.Math.Poly2.Galois.smul (Vale.Math.Poly2.Galois.to_poly e1) (Vale.Math.Poly2.Galois.to_poly e2) (Vale.Math.Poly2.Galois.irred_poly f) (Lib.IntTypes.bits (GF?.t f)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.op_disEquality", "Lib.IntTypes.U1", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Vale.Math.Poly2.Galois.lemma_smul_gmul_rec", "Prims.int", "Lib.IntTypes.bits", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Galois.to_poly", "Vale.Math.Poly2.Galois.gmul", "Vale.Math.Poly2.Galois.smul", "Vale.Math.Poly2.Galois.irred_poly", "Spec.GaloisField.__proj__GF__item__t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_smul_fmul (f: G.field) (e1 e2: G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t)) =
let G.GF t irred = f in let n = I.bits t in lemma_smul_gmul_rec f e1 e2 n
false
GTWP.fst
GTWP.t_return
val t_return (#a: _) (x: a) : m a T (as_pure_wp (fun p -> p x))
val t_return (#a: _) (x: a) : m a T (as_pure_wp (fun p -> p x))
let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 30, "start_col": 0, "start_line": 30 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> GTWP.m a GTWP.T (FStar.Monotonic.Pure.as_pure_wp (fun p -> p x))
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "GTWP.m", "GTWP.T", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre" ]
[]
false
false
false
false
false
let t_return #a (x: a) : m a T (as_pure_wp (fun p -> p x)) =
(fun () -> x)
false
GTWP.fst
GTWP.g_bind
val g_bind (#a #b #wc #wf: _) (c: m a G wc) (f: (x: a -> m b G (wf x))) : m b G (bind_wp wc wf)
val g_bind (#a #b #wc #wf: _) (c: m a G wc) (f: (x: a -> m b G (wf x))) : m b G (bind_wp wc wf)
let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) ()
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 152, "end_line": 45, "start_col": 0, "start_line": 45 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: GTWP.m a GTWP.G wc -> f: (x: a -> GTWP.m b GTWP.G (wf x)) -> GTWP.m b GTWP.G (GTWP.bind_wp wc wf)
Prims.Tot
[ "total" ]
[]
[ "GTWP.wp", "GTWP.m", "GTWP.G", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall", "GTWP.bind_wp" ]
[]
false
false
false
false
false
let g_bind #a #b #wc #wf (c: m a G wc) (f: (x: a -> m b G (wf x))) : m b G (bind_wp wc wf) =
elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) ()
false
Lib.ByteSequence.fst
Lib.ByteSequence.lemma_uints_to_bytes_le_sub
val lemma_uints_to_bytes_le_sub : #t : inttype{unsigned t /\ ~(U1? t)} -> #l : secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> s : lseq (uint_t t l) len -> i : size_nat {i < len} -> Lemma(sub (uints_to_bytes_le #t #l s) (i * numbytes t) (numbytes t) == uint_to_bytes_le (index s i))
val lemma_uints_to_bytes_le_sub : #t : inttype{unsigned t /\ ~(U1? t)} -> #l : secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> s : lseq (uint_t t l) len -> i : size_nat {i < len} -> Lemma(sub (uints_to_bytes_le #t #l s) (i * numbytes t) (numbytes t) == uint_to_bytes_le (index s i))
let lemma_uints_to_bytes_le_sub #t #l #len s i = let lemma_uints_to_bytes_le_i_j (j : size_nat {j < numbytes t}): Lemma(index (uints_to_bytes_le #t #l s) (i * numbytes t + j) == index (uint_to_bytes_le (index s i)) j) = index_uints_to_bytes_le #t #l #len s (i*numbytes t + j); assert (index (uints_to_bytes_le #t #l s) (i*numbytes t + j) == index (uint_to_bytes_le (index s i)) j) in Classical.forall_intro lemma_uints_to_bytes_le_i_j; eq_intro (sub (uints_to_bytes_le #t #l s) (i * numbytes t) (numbytes t)) (uint_to_bytes_le (index s i))
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 105, "end_line": 846, "start_col": 0, "start_line": 838 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i) let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; } let uints_to_bytes_le_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_le_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) (nat_to_bytes_le (len * numbytes t) n) val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1)) let index_nat_to_intseq_to_bytes_be #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc (==) { Seq.index (nat_to_bytes_be #l m (v s.[len - 1 - i / m])) (m - (i % m) - 1); == { index_nat_to_intseq_be #U8 #l m (v s.[len - 1 - i / m]) (i % m) } uint (v s.[len - 1 - i / m] / pow2 (8 * (i % m)) % pow2 8); == { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); == { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); == { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); } val uints_to_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i == Seq.index (nat_to_bytes_be (len * numbytes t) n) i) let uints_to_bytes_be_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in calc (==) { Seq.index (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) i; == { index_uints_to_bytes_be_aux #t #l len n i } Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_be #t #l len n (len * numbytes t - 1 - i)} Seq.index (nat_to_bytes_be (len * numbytes t) n) i; } let uints_to_bytes_be_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_be_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_be #t #l #len (nat_to_intseq_be #t #l len n)) (nat_to_bytes_be (len * numbytes t) n) #push-options "--max_fuel 1" let rec nat_from_intseq_le_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_le_inj (Seq.slice b1 1 (length b1)) (Seq.slice b2 1 (length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end let rec nat_from_intseq_be_inj #t #l b1 b2 = if length b1 = 0 then () else begin nat_from_intseq_be_inj (Seq.slice b1 0 (length b1 - 1)) (Seq.slice b2 0 (length b2 - 1)); Seq.lemma_split b1 (length b1 - 1); Seq.lemma_split b2 (length b2 - 1) end let lemma_nat_to_from_bytes_be_preserves_value #l b len x = () let lemma_nat_to_from_bytes_le_preserves_value #l b len x = () let lemma_uint_to_bytes_le_preserves_value #t #l x = () let lemma_uint_to_bytes_be_preserves_value #t #l x = () let lemma_nat_from_to_intseq_le_preserves_value #t #l len b = nat_from_intseq_le_inj (nat_to_intseq_le len (nat_from_intseq_le b)) b let lemma_nat_from_to_intseq_be_preserves_value #t #l len b = nat_from_intseq_be_inj (nat_to_intseq_be len (nat_from_intseq_be b)) b let lemma_nat_from_to_bytes_le_preserves_value #l b len = lemma_nat_from_to_intseq_le_preserves_value len b let lemma_nat_from_to_bytes_be_preserves_value #l b len = lemma_nat_from_to_intseq_be_preserves_value len b let lemma_reveal_uint_to_bytes_le #t #l b = () let lemma_reveal_uint_to_bytes_be #t #l b = () let lemma_uint_to_from_bytes_le_preserves_value #t #l i = lemma_reveal_uint_to_bytes_le #t #l (uint_to_bytes_le #t #l i); assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v (uint_from_bytes_le #t #l (uint_to_bytes_le #t #l i))); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i) let lemma_uint_to_from_bytes_be_preserves_value #t #l i = lemma_reveal_uint_to_bytes_be #t #l (uint_to_bytes_be #t #l i); lemma_uint_to_bytes_be_preserves_value #t #l i let lemma_uint_from_to_bytes_le_preserves_value #t #l s = let i = uint_from_bytes_le #t #l s in let s' = uint_to_bytes_le #t #l i in lemma_nat_from_to_bytes_le_preserves_value #l s' (length s'); assert(nat_to_bytes_le #l (length s') (nat_from_bytes_le s') == s'); lemma_uint_to_bytes_le_preserves_value #t #l i; assert(nat_from_bytes_le (uint_to_bytes_le #t #l i) == uint_v i); assert(s' == nat_to_bytes_le #l (length s') (uint_v i)); assert(s' == nat_to_bytes_le #l (length s') (uint_v (uint_from_bytes_le #t #l s))); lemma_reveal_uint_to_bytes_le #t #l s; assert(s' == nat_to_bytes_le #l (length s') (nat_from_bytes_le s)); lemma_nat_from_to_bytes_le_preserves_value #l s (length s) let lemma_uint_from_to_bytes_be_preserves_value #t #l s = let i = uint_from_bytes_be #t #l s in let s' = uint_to_bytes_be #t #l i in lemma_nat_from_to_bytes_be_preserves_value #l s' (length s'); assert(nat_to_bytes_be #l (length s') (nat_from_bytes_be s') == s'); lemma_uint_to_bytes_be_preserves_value #t #l i; assert(nat_from_bytes_be (uint_to_bytes_be #t #l i) == uint_v i); assert(s' == nat_to_bytes_be #l (length s') (uint_v i)); assert(s' == nat_to_bytes_be #l (length s') (uint_v (uint_from_bytes_be #t #l s))); lemma_reveal_uint_to_bytes_be #t #l s; assert(s' == nat_to_bytes_be #l (length s') (nat_from_bytes_be s)); lemma_nat_from_to_bytes_be_preserves_value #l s (length s) let rec nat_from_intseq_be_public_to_secret #t len b = if len = 1 then begin nat_from_intseq_be_lemma0 b; nat_from_intseq_be_lemma0 (map secret b) end else begin let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_be_public_to_secret #t (len - 1) b1; //assert (nat_from_intseq_be b1 == nat_from_intseq_be (map secret b1)); nat_from_intseq_be_slice_lemma b 1; nat_from_intseq_be_lemma0 (slice b 0 1); //assert (nat_from_intseq_be b == nat_from_intseq_be b1 + pow2 ((len - 1) * bits t) * v b.[0]); nat_from_intseq_be_slice_lemma b_secret 1; nat_from_intseq_be_lemma0 (slice b_secret 0 1); //assert (nat_from_intseq_be b_secret == nat_from_intseq_be b1_secret + pow2 ((len - 1) * bits t) * v b_secret.[0]); //assert (v b.[0] == v b_secret.[0]); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); () end let rec nat_from_intseq_le_public_to_secret #t len b = if len = 1 then begin nat_from_intseq_le_lemma0 b; nat_from_intseq_le_lemma0 (map secret b) end else begin let b_secret = map secret b in let b1 = slice b 1 len in let b1_secret = slice b_secret 1 len in nat_from_intseq_le_public_to_secret #t (len - 1) b1; //assert (nat_from_intseq_le b1 == nat_from_intseq_le (map secret b1)); nat_from_intseq_le_slice_lemma b 1; nat_from_intseq_le_lemma0 (slice b 0 1); //assert (nat_from_intseq_le b == nat_from_intseq_le (slice b 0 1) + pow2 (bits t) * nat_from_intseq_le (slice b 1 len)); nat_from_intseq_le_slice_lemma b_secret 1; nat_from_intseq_le_lemma0 (slice b_secret 0 1); eq_intro (slice (map secret b) 1 len) (map secret (slice b 1 len)); () end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Lib.Sequence.lseq (Lib.IntTypes.uint_t t l) len -> i: Lib.IntTypes.size_nat{i < len} -> FStar.Pervasives.Lemma (ensures Lib.Sequence.sub (Lib.ByteSequence.uints_to_bytes_le s) (i * Lib.IntTypes.numbytes t) (Lib.IntTypes.numbytes t) == Lib.ByteSequence.uint_to_bytes_le (Lib.Sequence.index s i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.l_not", "Lib.IntTypes.uu___is_U1", "Lib.IntTypes.secrecy_level", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Prims.pow2", "Lib.Sequence.lseq", "Lib.IntTypes.uint_t", "Lib.Sequence.eq_intro", "Lib.IntTypes.U8", "Lib.Sequence.sub", "Lib.ByteSequence.uints_to_bytes_le", "Lib.ByteSequence.uint_to_bytes_le", "Lib.Sequence.index", "Prims.unit", "FStar.Classical.forall_intro", "Prims.eq2", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Prims.op_Addition", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.l_True", "Prims.squash", "Lib.IntTypes.int_t", "Prims.op_Multiply", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "Lib.ByteSequence.index_uints_to_bytes_le" ]
[]
false
false
true
false
false
let lemma_uints_to_bytes_le_sub #t #l #len s i =
let lemma_uints_to_bytes_le_i_j (j: size_nat{j < numbytes t}) : Lemma (index (uints_to_bytes_le #t #l s) (i * numbytes t + j) == index (uint_to_bytes_le (index s i)) j) = index_uints_to_bytes_le #t #l #len s (i * numbytes t + j); assert (index (uints_to_bytes_le #t #l s) (i * numbytes t + j) == index (uint_to_bytes_le (index s i)) j) in Classical.forall_intro lemma_uints_to_bytes_le_i_j; eq_intro (sub (uints_to_bytes_le #t #l s) (i * numbytes t) (numbytes t)) (uint_to_bytes_le (index s i))
false
GTWP.fst
GTWP.return_wp
val return_wp (#a: _) (x: a) : wp a
val return_wp (#a: _) (x: a) : wp a
let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 35, "start_col": 0, "start_line": 34 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> GTWP.wp a
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre", "GTWP.wp" ]
[]
false
false
false
true
false
let return_wp #a (x: a) : wp a =
as_pure_wp (fun p -> p x)
false
Lib.ByteSequence.fst
Lib.ByteSequence.index_nat_to_intseq_to_bytes_be
val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1))
val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) == Seq.index (nat_to_bytes_be #l (len * numbytes t) n) (len * numbytes t - i - 1))
let index_nat_to_intseq_to_bytes_be #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc (==) { Seq.index (nat_to_bytes_be #l m (v s.[len - 1 - i / m])) (m - (i % m) - 1); == { index_nat_to_intseq_be #U8 #l m (v s.[len - 1 - i / m]) (i % m) } uint (v s.[len - 1 - i / m] / pow2 (8 * (i % m)) % pow2 8); == { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); == { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); == { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); }
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 695, "start_col": 0, "start_line": 682 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t))) let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0]) val uints_from_bytes_be_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b) let rec uints_from_bytes_be_nat_lemma_ #t #l #len b = if len = 0 then () else begin uints_from_bytes_be_nat_lemma_aux #t #l #len b; nat_from_intseq_be_slice_lemma_ b (numbytes t); uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t)) end let uints_from_bytes_be_nat_lemma #t #l #len b = uints_from_bytes_be_nat_lemma_ #t #l #len b #pop-options val index_uints_to_bytes_le_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (uints_to_bytes_le #t #l #len s) i == Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_le_aux #t #l len n i = let open Lib.Sequence in let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len s) i val index_uints_to_bytes_be_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (uints_to_bytes_be #t #l #len s) i == Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t)) let index_uints_to_bytes_be_aux #t #l len n i = let open Lib.Sequence in let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len s) i val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma ((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r) let modulo_pow2_prop r a b c = calc (==) { ((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r; == { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) } ((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r; == { Math.Lemmas.lemma_mul_sub_distr r b c } ((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r; == { Math.Lemmas.pow2_plus r (r * (b - c) - r) } (a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r; == { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))} (a / pow2 (r * c)) % pow2 r; } val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma (let m = numbytes t in n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 == n / pow2 (8 * i) % pow2 8) #push-options "--z3rlimit 150 --fuel 0 --ifuel 0" let some_arithmetic t n i = let m = numbytes t in calc (==) { n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8; == { assert (bits t == 8 * m) } n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { FStar.Math.Lemmas.paren_mul_right 8 m (i / m); FStar.Math.Lemmas.euclidean_division_definition i m } n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.distributivity_sub_right 8 i (i % m) } n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8; == { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) } (n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8; == { Math.Lemmas.division_multiplication_lemma n (pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) } (n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8; == { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) } (n / pow2 (8 * i)) % pow2 8; } #pop-options val index_nat_to_intseq_to_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t) == Seq.index (nat_to_bytes_le #l (len * numbytes t) n) i) let index_nat_to_intseq_to_bytes_le #t #l len n i = let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in let m = numbytes t in index_nat_to_intseq_le #U8 #l (len * m) n i; assert (Seq.index (nat_to_bytes_le #l (len * m) n) i == uint (n / pow2 (8 * i) % pow2 8)); index_nat_to_intseq_le #U8 #l m (v s.[i / m]) (i % m); assert (Seq.index (nat_to_bytes_le #l m (v s.[i / m])) (i % m) == uint (v s.[i / m] / pow2 (8 * (i % m)) % pow2 8)); index_nat_to_intseq_le #t #l len n (i / m); some_arithmetic t n i val uints_to_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i == Seq.index (nat_to_bytes_le (len * numbytes t) n) i) let uints_to_bytes_le_nat_lemma_ #t #l len n i = let s:lseq (uint_t t l) len = nat_to_intseq_le #t #l len n in calc (==) { Seq.index (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) i; == { index_uints_to_bytes_le_aux #t #l len n i } Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t); == { index_nat_to_intseq_to_bytes_le #t #l len n i} Seq.index (nat_to_bytes_le (len * numbytes t) n) i; } let uints_to_bytes_le_nat_lemma #t #l len n = Classical.forall_intro (uints_to_bytes_le_nat_lemma_ #t #l len n); eq_intro (uints_to_bytes_le #t #l #len (nat_to_intseq_le #t #l len n)) (nat_to_bytes_le (len * numbytes t) n) val index_nat_to_intseq_to_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> len:nat{len * numbytes t < pow2 32} -> n:nat{n < pow2 (bits t * len)} -> i:nat{i < len * numbytes t} -> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[len - 1 - i / numbytes t])) (numbytes t - 1 - i % numbytes t) ==
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Prims.nat{len * Lib.IntTypes.numbytes t < Prims.pow2 32} -> n: Prims.nat{n < Prims.pow2 (Lib.IntTypes.bits t * len)} -> i: Prims.nat{i < len * Lib.IntTypes.numbytes t} -> FStar.Pervasives.Lemma (ensures (let s = Lib.ByteSequence.nat_to_intseq_be len n in FStar.Seq.Base.index (Lib.ByteSequence.nat_to_bytes_be (Lib.IntTypes.numbytes t) (Lib.IntTypes.v s.[ len - 1 - i / Lib.IntTypes.numbytes t ])) (Lib.IntTypes.numbytes t - 1 - i % Lib.IntTypes.numbytes t) == FStar.Seq.Base.index (Lib.ByteSequence.nat_to_bytes_be (len * Lib.IntTypes.numbytes t) n) (len * Lib.IntTypes.numbytes t - i - 1)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.l_not", "Lib.IntTypes.uu___is_U1", "Lib.IntTypes.secrecy_level", "Prims.nat", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Prims.pow2", "Lib.IntTypes.bits", "FStar.Calc.calc_finish", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Prims.eq2", "FStar.Seq.Base.index", "Lib.ByteSequence.nat_to_bytes_be", "Lib.IntTypes.v", "Lib.Sequence.op_String_Access", "Lib.IntTypes.int_t", "Prims.op_Subtraction", "Prims.op_Division", "Prims.op_Modulus", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.IntTypes.uint", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.ByteSequence.index_nat_to_intseq_be", "Prims.squash", "Lib.ByteSequence.some_arithmetic", "Prims.int", "Lib.Sequence.lseq", "Lib.ByteSequence.nat_to_intseq_be" ]
[]
false
false
true
false
false
let index_nat_to_intseq_to_bytes_be #t #l len n i =
let s:lseq (uint_t t l) len = nat_to_intseq_be #t #l len n in let m = numbytes t in calc ( == ) { Seq.index (nat_to_bytes_be #l m (v s.[ len - 1 - i / m ])) (m - (i % m) - 1); ( == ) { index_nat_to_intseq_be #U8 #l m (v s.[ len - 1 - i / m ]) (i % m) } uint (v s.[ len - 1 - i / m ] / pow2 (8 * (i % m)) % pow2 8); ( == ) { index_nat_to_intseq_be #t #l len n (i / m) } uint ((n / pow2 (bits t * (i / m)) % pow2 (bits t)) / pow2 (8 * (i % m)) % pow2 8); ( == ) { some_arithmetic t n i } uint (n / pow2 (8 * i) % pow2 8); ( == ) { index_nat_to_intseq_be #U8 #l (len * m) n i } Seq.index (nat_to_bytes_be #l (len * m) n) (len * m - 1 - i); }
false
GTWP.fst
GTWP.t_bind
val t_bind (#a #b #wc #wf: _) (c: m a T wc) (f: (x: a -> m b T (wf x))) : m b T (bind_wp wc wf)
val t_bind (#a #b #wc #wf: _) (c: m a T wc) (f: (x: a -> m b T (wf x))) : m b T (bind_wp wc wf)
let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) ()
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 152, "end_line": 44, "start_col": 0, "start_line": 44 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: GTWP.m a GTWP.T wc -> f: (x: a -> GTWP.m b GTWP.T (wf x)) -> GTWP.m b GTWP.T (GTWP.bind_wp wc wf)
Prims.Tot
[ "total" ]
[]
[ "GTWP.wp", "GTWP.m", "GTWP.T", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall", "GTWP.bind_wp" ]
[]
false
false
false
false
false
let t_bind #a #b #wc #wf (c: m a T wc) (f: (x: a -> m b T (wf x))) : m b T (bind_wp wc wf) =
elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) ()
false
GTWP.fst
GTWP.bind
val bind (a b: Type) (i: idx) (wc: wp a) (wf: (a -> wp b)) (c: m a i wc) (f: (x: a -> m b i (wf x))) : m b i (bind_wp wc wf)
val bind (a b: Type) (i: idx) (wc: wp a) (wf: (a -> wp b)) (c: m a i wc) (f: (x: a -> m b i (wf x))) : m b i (bind_wp wc wf)
let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 56, "start_col": 0, "start_line": 51 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> i: GTWP.idx -> wc: GTWP.wp a -> wf: (_: a -> GTWP.wp b) -> c: GTWP.m a i wc -> f: (x: a -> GTWP.m b i (wf x)) -> GTWP.m b i (GTWP.bind_wp wc wf)
Prims.Tot
[ "total" ]
[]
[ "GTWP.idx", "GTWP.wp", "GTWP.m", "GTWP.t_bind", "GTWP.g_bind", "GTWP.coerce", "GTWP.D", "GTWP.bind_wp", "GTWP.d_bind", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall" ]
[]
false
false
false
false
false
let bind (a b: Type) (i: idx) (wc: wp a) (wf: (a -> wp b)) (c: m a i wc) (f: (x: a -> m b i (wf x))) : m b i (bind_wp wc wf) =
elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f)
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.malloc
val malloc: malloc_st (|Blake2S, M32|)
val malloc: malloc_st (|Blake2S, M32|)
let malloc = BlS32.malloc_with_key
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 13, "start_col": 0, "start_line": 13 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.malloc_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Blake2s_32.malloc_with_key" ]
[]
false
false
false
false
false
let malloc =
BlS32.malloc_with_key
false
Lib.ByteSequence.fst
Lib.ByteSequence.uints_from_bytes_be_nat_lemma_aux
val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t)))
val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t)))
let uints_from_bytes_be_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0])
{ "file_name": "lib/Lib.ByteSequence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 113, "end_line": 532, "start_col": 0, "start_line": 528 }
module Lib.ByteSequence open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.RawIntTypes open Lib.LoopCombinators #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" /// BEGIN constant-time sequence equality val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat -> k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } -> Lemma (requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) (ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k))) let lemma_not_equal_slice #a b1 b2 i j k = assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i)) val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} -> Lemma (requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1))) (ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j))) let lemma_not_equal_last #a b1 b2 i j = Seq.lemma_index_slice b1 i j (j - i - 1); Seq.lemma_index_slice b2 i j (j - i - 1) val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat -> b1:lseq (int_t t SEC) len1 -> b2:lseq (int_t t SEC) len2 -> len:size_nat{len <= len1 /\ len <= len2} -> i:size_nat{i < len} -> res:int_t t SEC{ (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))} -> res':int_t t SEC{ (sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\ (sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))} let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res = logand_zeros (ones t SEC); logand_ones (ones t SEC); logand_zeros (zeros t SEC); logand_ones (zeros t SEC); let z0 = res in let res = eq_mask b1.[i] b2.[i] &. z0 in logand_spec (eq_mask b1.[i] b2.[i]) z0; if v res = ones_v t then begin let s1 = sub b1 0 (i + 1) in let s2 = sub b2 0 (i + 1) in Seq.lemma_split s1 i; Seq.lemma_split s2 i; assert (equal s1 s2) end else if v z0 = 0 then lemma_not_equal_slice b1 b2 0 i (i + 1) else lemma_not_equal_last b1 b2 0 (i + 1); res let seq_eq_mask #t #len1 #len2 b1 b2 len = repeati_inductive len (fun (i:nat{i <= len}) res -> (sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\ (sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))) (seq_eq_mask_inner b1 b2 len) (ones t SEC) let lbytes_eq #len b1 b2 = let res = seq_eq_mask b1 b2 len in RawIntTypes.u8_to_UInt8 res = 255uy /// END constant-time sequence equality let mask_select #t mask a b = b ^. (mask &. (a ^. b)) let mask_select_lemma #t mask a b = let t1 = mask &. (a ^. b) in let t2 = b ^. t1 in logand_lemma mask (a ^.b); if v mask = 0 then begin assert (v t1 == 0); logxor_lemma b t1; assert (v t2 = v b); () end else begin assert (v t1 == v (a ^. b)); logxor_lemma b a; assert (v t2 = v a); () end let seq_mask_select #t #len a b mask = let res = map2 (mask_select mask) a b in let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) = mask_select_lemma mask a.[i] b.[i] in Classical.forall_intro lemma_aux; if v mask = 0 then eq_intro res b else eq_intro res a; res val nat_from_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_be_ #t #l b = let len = length b in if len = 0 then 0 else let l = v (Seq.index b (len - 1)) in let pre = Seq.slice b 0 (len - 1) in let shift = pow2 (bits t) in let n' = nat_from_intseq_be_ pre in Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t); l + shift * n' let nat_from_intseq_be = nat_from_intseq_be_ val nat_from_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> b:seq (uint_t t l) -> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b)) let rec nat_from_intseq_le_ #t #l b = let len = length b in if len = 0 then 0 else let shift = pow2 (bits t) in let tt = Seq.slice b 1 len in let n' = nat_from_intseq_le_ #t #l tt in let l = v (Seq.index b 0) in Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t); let n = l + shift * n' in n let nat_from_intseq_le = nat_from_intseq_le_ #set-options "--max_fuel 1" val nat_to_intseq_be_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len) let rec nat_to_intseq_be_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_be_ len' n' in let b = Seq.append b' (create 1 tt) in Seq.append_slices b' (create 1 tt); b let nat_to_intseq_be = nat_to_intseq_be_ val nat_to_intseq_le_: #t:inttype{unsigned t} -> #l:secrecy_level -> len:nat -> n:nat{n < pow2 (bits t * len)} -> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len) let rec nat_to_intseq_le_ #t #l len n = if len = 0 then Seq.empty else let len' = len - 1 in let tt = uint #t #l (n % modulus t) in let n' = n / modulus t in assert (modulus t = pow2 (bits t)); FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); let b' = nat_to_intseq_le_ len' n' in let b = Seq.append (create 1 tt) b' in Seq.append_slices (create 1 tt) b'; b let nat_to_intseq_le = nat_to_intseq_le_ /// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using /// fuel > 0 below, which makes the proof more expensive val head_nat_to_intseq_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_le #t #l len n = () val nat_to_intseq_le_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_le #t #l len n == Seq.append (create 1 (uint #t #l (n % modulus t))) (nat_to_intseq_le (len - 1) (n / modulus t))) let nat_to_intseq_le_pos #t #l len n = () val head_nat_to_intseq_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) == uint #t #l (n % pow2 (bits t))) let head_nat_to_intseq_be #t #l len n = () val nat_to_intseq_be_pos: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_pos -> n:nat{n < pow2 (bits t * len)} -> Lemma (nat_to_intseq_be #t #l len n == Seq.append (nat_to_intseq_be (len - 1) (n / modulus t)) (create 1 (uint #t #l (n % modulus t)))) let nat_to_intseq_be_pos #t #l len n = () #push-options "--fuel 0 --ifuel 0" let rec index_nat_to_intseq_le #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_le #t #l len n else begin FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1); == { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) } uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t); == { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) } uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t); == { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) } uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t); == { Math.Lemmas.distributivity_add_right (bits t) i (-1) } uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t); == { } uint (n / pow2 (bits t * i) % pow2 (bits t)); }; nat_to_intseq_le_pos #t #l len n end let rec index_nat_to_intseq_be #t #l len n i = if i = 0 then if len = 0 then () else head_nat_to_intseq_be #t #l len n else begin let len' = len - 1 in let i' = i - 1 in let n' = n / pow2 (bits t) in FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t); calc (==) { Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1); == {index_nat_to_intseq_be #t #l len' n' i'} uint (n' / pow2 (bits t * i') % pow2 (bits t)); == {} uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t)); == {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))} uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t)); == {Math.Lemmas.pow2_plus (bits t) (bits t * i')} uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t)); == {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)} uint (n / (pow2 (bits t * i)) % pow2 (bits t)); }; nat_to_intseq_be_pos #t #l len n end let uint_to_bytes_le #t #l n = nat_to_bytes_le (numbytes t) (v n) let index_uint_to_bytes_le #t #l u = Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u)) let uint_to_bytes_be #t #l n = nat_to_bytes_be (numbytes t) (v n) let index_uint_to_bytes_be #t #l u = Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u)) let uint_from_bytes_le #t #l b = let n = nat_from_intseq_le #U8 b in uint #t #l n let uint_from_bytes_be #t #l b = let n = nat_from_intseq_be #U8 b in uint #t #l n val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_le_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_le #t #l b.[i] let uints_to_bytes_le #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_le_inner #t #l #len ul) () in o (* Could also be written more simply as: let uints_to_bytes_le #t #l #len ul = createi (len * numbytes t) (fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in s.[i % numbytes t]) *) let index_uints_to_bytes_le #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> lseq (int_t t l) len -> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t)) let uints_to_bytes_be_inner #t #l #len b i () = let open Lib.Sequence in (), uint_to_bytes_be #t #l b.[i] let uints_to_bytes_be #t #l #len ul = let a_spec (i:nat{i <= len}) = unit in let _, o = generate_blocks (numbytes t) len len a_spec (uints_to_bytes_be_inner #t #l #len ul) () in o let index_uints_to_bytes_be #t #l #len ul i = index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i let uints_from_bytes_le #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_le #t #l #len b i = () let uints_from_bytes_be #t #l #len b = Lib.Sequence.createi #(int_t t l) len (fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))) let index_uints_from_bytes_be #t #l #len b i = () let uint_at_index_le #t #l #len b i = uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)) let uint_at_index_be #t #l #len b i = uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)) #push-options "--max_fuel 1" val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} -> Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b) let nat_from_intseq_slice_lemma_aux len a b c i = FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b); FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b; FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c val nat_from_intseq_le_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len)) let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = 0 then () else begin let b1 = slice b 0 i in nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1); assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]); nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len)); nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i end end let nat_from_intseq_le_lemma0 #t #l b = () let nat_from_intseq_le_slice_lemma #t #l #len b i = nat_from_intseq_le_slice_lemma_ b i val nat_from_intseq_be_slice_lemma_: #t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat -> b:lseq (int_t t l) len -> i:nat{i <= len} -> Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i))) (decreases (len - i)) let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i = if len = 0 then () else begin if i = len then () else begin let b1 = slice b i len in nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1; assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]); nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1); assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1))); nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i) end end let nat_from_intseq_be_lemma0 #t #l b = () #pop-options let nat_from_intseq_be_slice_lemma #t #l #len b i = nat_from_intseq_be_slice_lemma_ #t #l #len b i val uints_from_bytes_le_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_le #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_le_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_le #t #l #(j-i) b1 in index_uints_from_bytes_le #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_le_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) #push-options "--max_fuel 1" val uints_from_bytes_le_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))) let uints_from_bytes_le_nat_lemma_aux #t #l #len b = let r = uints_from_bytes_le #t #l #len b in assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len)); assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]); uints_from_bytes_le_slice_lemma #t #l #len b 1 len; assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) val uints_from_bytes_le_nat_lemma_: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_nat{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b) let rec uints_from_bytes_le_nat_lemma_ #t #l #len b = if len = 0 then () else begin let b1 = slice b (numbytes t) (len * numbytes t) in nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t); assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1; assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1); uints_from_bytes_le_nat_lemma_aux #t #l #len b end let uints_from_bytes_le_nat_lemma #t #l #len b = uints_from_bytes_le_nat_lemma_ #t #l #len b val uints_from_bytes_be_slice_lemma_lp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k = let r = slice (uints_from_bytes_le #t #l #len b) i j in index_uints_from_bytes_be #t #l #len b (i + k); assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma_rp: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} -> Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k = let b1 = slice b (i * numbytes t) (j * numbytes t) in let r = uints_from_bytes_be #t #l #(j-i) b1 in index_uints_from_bytes_be #t #l #(j-i) b1 k; assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t))); assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t))) val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) let uints_from_bytes_be_slice_lemma #t #l #len b i j = FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j); FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j); eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) val uints_from_bytes_be_nat_lemma_aux: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32} -> b:lbytes_l l (len * numbytes t) -> Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.ByteSequence.fst" }
[ { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes_l l (len * Lib.IntTypes.numbytes t) -> FStar.Pervasives.Lemma (ensures Lib.ByteSequence.nat_from_intseq_be_ (Lib.ByteSequence.uints_from_bytes_be b) == Lib.ByteSequence.nat_from_intseq_be (Lib.ByteSequence.uints_from_bytes_be (Lib.Sequence.slice b (Lib.IntTypes.numbytes t) (len * Lib.IntTypes.numbytes t))) + Prims.pow2 ((len - 1) * Lib.IntTypes.bits t) * Lib.ByteSequence.nat_from_intseq_be_ (Lib.Sequence.slice b 0 (Lib.IntTypes.numbytes t)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.l_not", "Lib.IntTypes.uu___is_U1", "Lib.IntTypes.secrecy_level", "Lib.IntTypes.size_pos", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Prims.pow2", "Lib.ByteSequence.lbytes_l", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.ByteSequence.nat_from_intseq_be_", "Prims.op_Addition", "Lib.ByteSequence.nat_from_intseq_be", "Lib.Sequence.slice", "Lib.IntTypes.uint_t", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Lib.IntTypes.uint_v", "Lib.Sequence.op_String_Access", "Prims.unit", "Lib.ByteSequence.nat_from_intseq_be_slice_lemma", "Lib.ByteSequence.uints_from_bytes_be_slice_lemma", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.ByteSequence.uints_from_bytes_be" ]
[]
true
false
true
false
false
let uints_from_bytes_be_nat_lemma_aux #t #l #len b =
let r = uints_from_bytes_be #t #l #len b in uints_from_bytes_be_slice_lemma #t #l #len b 1 len; nat_from_intseq_be_slice_lemma r 1; assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[ 0 ])
false
GTWP.fst
GTWP.d_return
val d_return (#a: _) (x: a) : m a D (as_pure_wp (fun p -> p x))
val d_return (#a: _) (x: a) : m a D (as_pure_wp (fun p -> p x))
let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 83, "end_line": 32, "start_col": 0, "start_line": 32 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> GTWP.m a GTWP.D (FStar.Monotonic.Pure.as_pure_wp (fun p -> p x))
Prims.Tot
[ "total" ]
[]
[ "FStar.Universe.raise_val", "Prims.unit", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre", "GTWP.m", "GTWP.D" ]
[]
false
false
false
false
false
let d_return #a (x: a) : m a D (as_pure_wp (fun p -> p x)) =
raise_val (fun () -> x)
false
GTWP.fst
GTWP.subcomp
val subcomp (a: Type u#aa) (i: idx) (wp1 wp2: wp a) (f: m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True))
val subcomp (a: Type u#aa) (i: idx) (wp1 wp2: wp a) (f: m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True))
let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 75, "start_col": 0, "start_line": 59 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> i: GTWP.idx -> wp1: GTWP.wp a -> wp2: GTWP.wp a -> f: GTWP.m a i wp1 -> Prims.Pure (GTWP.m a i wp2)
Prims.Pure
[]
[]
[ "GTWP.idx", "GTWP.wp", "GTWP.m", "GTWP.coerce", "FStar.Universe.raise_t", "Prims.unit", "FStar.Universe.raise_val", "FStar.Pervasives.assert_norm", "Prims.eq2", "FStar.Universe.downgrade_val", "Prims.l_Forall", "Prims.pure_post", "Prims.l_imp", "Prims.l_True" ]
[]
false
false
false
false
false
let subcomp (a: Type u#aa) (i: idx) (wp1 wp2: wp a) (f: m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) =
match i with | T -> f | G -> f | D -> let f:raise_t (unit -> DIV a wp1) = f in let f: unit -> DIV a wp1 = downgrade_val f in let f: unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f)
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.init
val init: init_st (|Blake2S, M32|)
val init: init_st (|Blake2S, M32|)
let init s = BlS32.init s 0ul 32ul
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 24, "start_col": 0, "start_line": 24 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.init_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Hash.Definitions.state", "Prims.Mkdtuple2", "Spec.Hash.Definitions.hash_alg", "Hacl.Hash.Definitions.m_spec", "Spec.Hash.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.init", "FStar.UInt32.__uint_to_t", "Prims.unit" ]
[]
false
false
false
false
false
let init s =
BlS32.init s 0ul 32ul
false
GTWP.fst
GTWP.ite_wp
val ite_wp (#a: _) (w1 w2: wp a) (b: bool) : wp a
val ite_wp (#a: _) (w1 w2: wp a) (b: bool) : wp a
let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 80, "start_col": 0, "start_line": 78 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w1: GTWP.wp a -> w2: GTWP.wp a -> b: Prims.bool -> GTWP.wp a
Prims.Tot
[ "total" ]
[]
[ "GTWP.wp", "Prims.bool", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall" ]
[]
false
false
false
true
false
let ite_wp #a (w1: wp a) (w2: wp a) (b: bool) : wp a =
elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p)
false
GTWP.fst
GTWP.map
val map (#a #b #i: _) (f: (a -> Gtd b i)) (xs: list a) : Gtd (list b) i
val map (#a #b #i: _) (f: (a -> Gtd b i)) (xs: list a) : Gtd (list b) i
let rec map #a #b #i (f : a -> Gtd b i) (xs : list a) : Gtd (list b) i (* by (explode (); dump "") *) = match xs with | [] -> [] | x::xs -> (f x)::(map f xs)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 135, "start_col": 0, "start_line": 132 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) unfold let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x) effect Gtd (a:Type) (i:idx) = GTD a i (null_wp a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: a -> GTWP.Gtd b) -> xs: Prims.list a -> GTWP.Gtd (Prims.list b)
GTWP.Gtd
[]
[]
[ "GTWP.idx", "Prims.list", "Prims.Nil", "Prims.Cons", "GTWP.map" ]
[ "recursion" ]
false
true
false
false
false
let rec map #a #b #i (f: (a -> Gtd b i)) (xs: list a) : Gtd (list b) i =
match xs with | [] -> [] | x :: xs -> (f x) :: (map f xs)
false
GTWP.fst
GTWP.null_wp
val null_wp (a: Type) : pure_wp a
val null_wp (a: Type) : pure_wp a
let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x)
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 128, "start_col": 0, "start_line": 128 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Prims.pure_wp a
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.l_Forall", "Prims.l_True", "Prims.pure_pre", "Prims.pure_wp" ]
[]
false
false
false
true
false
let null_wp (a: Type) : pure_wp a =
as_pure_wp (fun p -> forall x. p x)
false
GTWP.fst
GTWP.lift_pure_gtd
val lift_pure_gtd (a: Type) (w: wp a) (i: idx) (f: (unit -> PURE a w)) : Pure (m a i w) (requires True) (ensures (fun _ -> True))
val lift_pure_gtd (a: Type) (w: wp a) (i: idx) (f: (unit -> PURE a w)) : Pure (m a i w) (requires True) (ensures (fun _ -> True))
let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f''
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 113, "start_col": 0, "start_line": 102 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> w: GTWP.wp a -> i: GTWP.idx -> f: (_: Prims.unit -> Prims.PURE a) -> Prims.Pure (GTWP.m a i w)
Prims.Pure
[]
[]
[ "GTWP.wp", "GTWP.idx", "Prims.unit", "GTWP.m", "GTWP.D", "FStar.Universe.raise_val", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall", "Prims.l_True" ]
[]
false
false
false
false
false
let lift_pure_gtd (a: Type) (w: wp a) (i: idx) (f: (unit -> PURE a w)) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) =
elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'':m a D w = raise_val f' in f''
false
GTWP.fst
GTWP.labs
val labs (#i: _) (n: int) : Gtd nat i
val labs (#i: _) (n: int) : Gtd nat i
let labs #i (n:int) : Gtd nat i = if n < 0 then -n else n
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 162, "start_col": 0, "start_line": 159 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) unfold let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x) effect Gtd (a:Type) (i:idx) = GTD a i (null_wp a) let rec map #a #b #i (f : a -> Gtd b i) (xs : list a) : Gtd (list b) i (* by (explode (); dump "") *) = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) let app #a #b #i #wp (f : a -> GTD b i wp) (x : a) : GTD b i wp = f x open FStar.Tactics.V2 let rec appn #a #i (n:nat) (f : a -> Gtd a i) (x : a) : Gtd a i = match n with | 0 -> x | _ -> begin appn (n-1) f (f x) end // explodes //[@@expect_failure] //let test #a #i (n:int) : Gtd nat i = // let r = app abs n in // r let labs0 #i (n:int) : Gtd int i = if n < 0 then -n else n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.int -> GTWP.Gtd Prims.nat
GTWP.Gtd
[]
[]
[ "GTWP.idx", "Prims.int", "Prims.op_LessThan", "Prims.op_Minus", "Prims.bool", "Prims.nat" ]
[]
false
true
false
false
false
let labs #i (n: int) : Gtd nat i =
if n < 0 then - n else n
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_fmul_fmul
val lemma_fmul_fmul (f: G.field) (a b: G.felem f) : Lemma (G.fmul a b == fmul f a b)
val lemma_fmul_fmul (f: G.field) (a b: G.felem f) : Lemma (G.fmul a b == fmul f a b)
let lemma_fmul_fmul (f:G.field) (a b:G.felem f) : Lemma (G.fmul a b == fmul f a b) = let repeati = Lib.LoopCombinators.repeati in let acc0 = (G.zero #f, a, b) in let rec lem (n:nat{n < I.bits f.G.t}) (f1:(i:nat{i < n} -> fmul_t f -> fmul_t f)) : Lemma (requires (forall (i:nat{i < n}) (pab:fmul_t f). f1 i pab == fmul_iter f i pab)) (ensures repeati n (fmul_iter f) acc0 == repeati n f1 acc0) [SMTPat (repeati n f1 acc0)] = if n = 0 then ( let pred (n:nat) (pab:(fmul_t f)) : Type0 = n == 0 ==> pab == acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred (fmul_iter f) acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred f1 acc0 in () ) else ( lem (n - 1) f1; Lib.LoopCombinators.unfold_repeati n (fmul_iter f) acc0 (n - 1); Lib.LoopCombinators.unfold_repeati n f1 acc0 (n - 1); assert (repeati n (fmul_iter f) acc0 == repeati n f1 acc0); () ) in ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 573, "start_col": 0, "start_line": 547 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); () #reset-options "--z3rlimit 20" let rec lemma_smul_gmul_rec (f:G.field) (e1 e2:G.felem f) (n:nat) : Lemma ( let (p, a, b) = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) = let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then ( lemma_smul_gmul_rec f e1 e2 (n - 1); let (sp, sa, sb) = smul_rec a b m (n - 1) in let (gp, ga, gb) = gmul_rec f e1 e2 (n - 1) in //assert (to_poly gp == sp); //assert (to_poly ga == sa); //assert (to_poly gb == sb); let sp' = sp +. (if sb.[0] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in // mod_bit1 is equivalent to mod in this case let sb' = shift sb (-1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[k - 1] then m_lo else zero in let ssa' = ssa +. ssa_add in //assert (sa' == ssa'); let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[0] then lemma_equal (sb &. one) one; //assert (sb.[0] <==> I.v (I.logand gb (G.one #f)) = I.v (G.one #f)); lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); //assert (to_poly gp' == sp'); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; //assert (to_poly f.G.irred == m_lo); lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); //assert (to_poly carry_irred == ssa_add); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); //assert (to_poly ga_shift == ssa); //assert (to_poly ga' == ssa'); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); //assert (to_poly gb' == sb'); () ) let lemma_smul_fmul (f:G.field) (e1 e2:G.felem f) : Lemma (to_poly (gmul f e1 e2) == smul (to_poly e1) (to_poly e2) (irred_poly f) (I.bits f.G.t)) = let G.GF t irred = f in let n = I.bits t in lemma_smul_gmul_rec f e1 e2 n let lemma_fmul_gmul (f:G.field) (a b:G.felem f) : Lemma (fmul f a b == gmul f a b) = let pred (n:nat) (pab:(fmul_t f)) : Type0 = gmul_rec f a b n == pab in let _ = Lib.LoopCombinators.repeati_inductive' (I.bits f.G.t - 1) pred (fmul_iter f) (G.zero #f, a, b) in () #reset-options "--initial_ifuel 1"
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 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" }
false
f: Spec.GaloisField.field -> a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> FStar.Pervasives.Lemma (ensures Spec.GaloisField.fmul a b == Vale.Math.Poly2.Galois.fmul f a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.bits", "Spec.GaloisField.__proj__GF__item__t", "Vale.Math.Poly2.Galois.fmul_t", "Prims.unit", "Prims.l_Forall", "Prims.eq2", "Vale.Math.Poly2.Galois.fmul_iter", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.repeati_inductive'", "Prims.l_imp", "FStar.Pervasives.Native.tuple3", "Prims.bool", "Prims._assert", "Lib.LoopCombinators.unfold_repeati", "Prims.op_Subtraction", "FStar.Pervasives.Native.Mktuple3", "Spec.GaloisField.zero", "Lib.LoopCombinators.repeati", "Prims.l_True", "Spec.GaloisField.fmul", "Vale.Math.Poly2.Galois.fmul" ]
[]
false
false
true
false
false
let lemma_fmul_fmul (f: G.field) (a b: G.felem f) : Lemma (G.fmul a b == fmul f a b) =
let repeati = Lib.LoopCombinators.repeati in let acc0 = (G.zero #f, a, b) in let rec lem (n: nat{n < I.bits f.G.t}) (f1: (i: nat{i < n} -> fmul_t f -> fmul_t f)) : Lemma (requires (forall (i: nat{i < n}) (pab: fmul_t f). f1 i pab == fmul_iter f i pab)) (ensures repeati n (fmul_iter f) acc0 == repeati n f1 acc0) [SMTPat (repeati n f1 acc0)] = if n = 0 then (let pred (n: nat) (pab: (fmul_t f)) : Type0 = n == 0 ==> pab == acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred (fmul_iter f) acc0 in let _ = Lib.LoopCombinators.repeati_inductive' 0 pred f1 acc0 in ()) else (lem (n - 1) f1; Lib.LoopCombinators.unfold_repeati n (fmul_iter f) acc0 (n - 1); Lib.LoopCombinators.unfold_repeati n f1 acc0 (n - 1); assert (repeati n (fmul_iter f) acc0 == repeati n f1 acc0); ()) in ()
false
GTWP.fst
GTWP.appn
val appn (#a #i: _) (n: nat) (f: (a -> Gtd a i)) (x: a) : Gtd a i
val appn (#a #i: _) (n: nat) (f: (a -> Gtd a i)) (x: a) : Gtd a i
let rec appn #a #i (n:nat) (f : a -> Gtd a i) (x : a) : Gtd a i = match n with | 0 -> x | _ -> begin appn (n-1) f (f x) end
{ "file_name": "examples/layeredeffects/GTWP.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 146, "start_col": 0, "start_line": 141 }
module GTWP open FStar.Tactics.V2 open FStar.Universe open FStar.Monotonic.Pure type idx = | T | G | D // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x // GM: Warning: the [unfold]s here are important. let wp (a:Type) = pure_wp a unfold let bind_wp #a #b (wc : wp a) (wf : a -> wp b) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wc (fun x -> wf x p)) let m (a:Type u#aa) (i:idx) (w : wp a) : Type u#aa = match i with | T -> unit -> PURE a w | G -> unit -> GHOST a w | D -> raise_t (unit -> DIV a w) let t_return #a (x:a) : m a T (as_pure_wp (fun p -> p x)) = (fun () -> x) let g_return #a (x:a) : m a G (as_pure_wp (fun p -> p x)) = (fun () -> x) let d_return #a (x:a) : m a D (as_pure_wp (fun p -> p x)) = raise_val (fun () -> x) let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a:Type) (x:a) (i:idx) : m a i (return_wp x) = match i with | T -> t_return x | G -> g_return x | D -> coerce (d_return x) // these two rely on monotonicity since the computed WP is not exactly bind_wp let t_bind #a #b #wc #wf (c : m a T wc) (f : (x:a -> m b T (wf x))) : m b T (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let g_bind #a #b #wc #wf (c : m a G wc) (f : (x:a -> m b G (wf x))) : m b G (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); fun () -> f (c ()) () let d_bind #a #b #wc #wf (c : m a D wc) (f : (x:a -> m b D (wf x))) : m b D (bind_wp wc wf) = raise_val (fun () -> let y = downgrade_val c () in // cannot inline this downgrade_val (f y) ()) let bind (a b : Type) (i:idx) (wc:wp a) (wf:a -> wp b) (c : m a i wc) (f : (x:a -> m b i (wf x))) : m b i (bind_wp wc wf) = elim_pure_wp_monotonicity_forall (); match i with | T -> t_bind #_ #_ #wc #wf c f | G -> g_bind #_ #_ #wc #wf c f | D -> coerce (d_bind #_ #_ #wc #wf (coerce c) f) // GM: would be nice to skip the annotations. let subcomp (a:Type u#aa) (i:idx) (wp1 : wp a) (wp2 : wp a) (f : m a i wp1) : Pure (m a i wp2) (requires (forall p. wp2 p ==> wp1 p)) (ensures (fun _ -> True)) = match i with | T -> f | G -> f | D -> (* This case needs some handholding. *) let f : raise_t (unit -> DIV a wp1) = f in let f : unit -> DIV a wp1 = downgrade_val f in let f : unit -> DIV a wp2 = f in assert_norm (m a i wp2 == raise_t (unit -> DIV a wp2)); coerce (raise_val f) unfold let ite_wp #a (w1 w2 : wp a) (b:bool) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> if b then w1 p else w2 p) let if_then_else (a:Type) (i:idx) (w1 w2 : wp a) (f : m a i w1) (g : m a i w2) (b : bool) : Type = m a i (ite_wp w1 w2 b) // GM: Would be nice to not have to use all explicit args everywhere, // and to get better errors especially when args are out of order, // e.g. the [idx] in [return] needs to come after [x], otherwise // we get an assertion failure trying to prove [forall (a: Type). idx == a]. reifiable reflectable effect { GTD (a:Type) ([@@@ effect_param] _:idx) (_:wp a) with { repr = m; return; bind; subcomp; if_then_else; } } let lift_pure_gtd (a:Type) (w : wp a) (i : idx) (f : unit -> PURE a w) : Pure (m a i w) (requires True) (ensures (fun _ -> True)) = elim_pure_wp_monotonicity_forall (); match i with | T -> f | G -> f | D -> let f' () : DIV a w = f () in let f'' : m a D w = raise_val f' in f'' // GM: Surprised that this works actually... I expected that I would need to // case analyze [i]. // GM: not anymore whe Div is involved, also need a lot of scaffolding sub_effect PURE ~> GTD = lift_pure_gtd [@@ expect_failure] // wp is not specified let rec map #a #b #i (f : a -> GTD b i) (xs : list a) : GTD (list b) i = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) unfold let null_wp (a:Type) : pure_wp a = as_pure_wp (fun p -> forall x. p x) effect Gtd (a:Type) (i:idx) = GTD a i (null_wp a) let rec map #a #b #i (f : a -> Gtd b i) (xs : list a) : Gtd (list b) i (* by (explode (); dump "") *) = match xs with | [] -> [] | x::xs -> (f x)::(map f xs) let app #a #b #i #wp (f : a -> GTD b i wp) (x : a) : GTD b i wp = f x open FStar.Tactics.V2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked" ], "interface_file": false, "source_file": "GTWP.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Universe", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> f: (_: a -> GTWP.Gtd a) -> x: a -> GTWP.Gtd a
GTWP.Gtd
[]
[]
[ "GTWP.idx", "Prims.nat", "Prims.int", "GTWP.appn", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec appn #a #i (n: nat) (f: (a -> Gtd a i)) (x: a) : Gtd a i =
match n with | 0 -> x | _ -> appn (n - 1) f (f x)
false
LowStar.Endianness.fst
LowStar.Endianness.store_post
val store_post : b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> i: Prims.nat -> j: Prims.nat{i + j <= LowStar.Monotonic.Buffer.length b} -> predicate: (_: FStar.Seq.Base.seq a -> Type0) -> h0: FStar.Monotonic.HyperStack.mem -> _: Prims.unit -> h1: FStar.Monotonic.HyperStack.mem -> Prims.GTot Prims.logical
let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j)))
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 102, "start_col": 7, "start_line": 89 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> i: Prims.nat -> j: Prims.nat{i + j <= LowStar.Monotonic.Buffer.length b} -> predicate: (_: FStar.Seq.Base.seq a -> Type0) -> h0: FStar.Monotonic.HyperStack.mem -> _: Prims.unit -> h1: FStar.Monotonic.HyperStack.mem -> Prims.GTot Prims.logical
Prims.GTot
[ "sometrivial" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "LowStar.Monotonic.Buffer.length", "FStar.Seq.Base.seq", "FStar.Monotonic.HyperStack.mem", "Prims.unit", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "Prims.logical" ]
[]
false
false
false
false
true
let store_post (#a: Type) (#rrel #rel: MB.srel a) (b: MB.mbuffer a rrel rel) (i: nat) (j: nat{i + j <= MB.length b}) (predicate: (Seq.seq a -> Type0)) =
fun (h0: HS.mem) (_: unit) (h1: HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j)))
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.hash
val hash: hash_st Blake2S
val hash: hash_st Blake2S
let hash output input input_len = Hacl.Streaming.Blake2s_32.hash_with_key output 32ul input input_len (null #MUT uint8) 0ul
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 123, "end_line": 40, "start_col": 0, "start_line": 40 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s let init s = BlS32.init s 0ul 32ul let update_multi s ev blocks n = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_multi #(n `FStar.UInt32.mul` block_len Blake2S) wv s (secret ev) blocks n; ST.pop_frame () let update_last s prev input input_len = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_last #input_len wv s (secret prev) input_len input; ST.pop_frame() let finish s dst = BlS32.finish (hash_len Blake2S) dst s
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.Blake2S
Prims.Tot
[ "total" ]
[]
[ "Hacl.Hash.Definitions.hash_t", "Spec.Hash.Definitions.Blake2S", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.IntTypes.U32", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Hacl.Streaming.Blake2s_32.hash_with_key", "FStar.UInt32.__uint_to_t", "Lib.Buffer.null", "Lib.Buffer.MUT", "Prims.unit" ]
[]
false
false
false
true
false
let hash output input input_len =
Hacl.Streaming.Blake2s_32.hash_with_key output 32ul input input_len (null #MUT uint8) 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.load64_le
val load64_le (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z))
val load64_le (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z))
let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 357, "start_col": 0, "start_line": 350 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 8} -> FStar.HyperStack.ST.Stack FStar.UInt64.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load64_le_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u64", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt64.v" ]
[]
false
true
false
false
false
let load64_le (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) =
load64_le_i b 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.store16_le
val store16_le (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z))
val store16_le (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z))
let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 268, "start_col": 0, "start_line": 260 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 2} -> z: FStar.UInt16.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt16.t", "LowStar.Endianness.store16_le_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt16.n", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt16.v" ]
[]
false
true
false
false
false
let store16_le (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) =
store16_le_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.load16_be
val load16_be (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z))
val load16_be (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z))
let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 297, "start_col": 0, "start_line": 290 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 2} -> FStar.HyperStack.ST.Stack FStar.UInt16.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load16_be_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u16", "FStar.UInt16.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt16.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt16.v" ]
[]
false
true
false
false
false
let load16_be (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) =
load16_be_i b 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.store_pre
val store_pre : b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> i: Prims.nat -> j: Prims.nat{i + j <= LowStar.Monotonic.Buffer.length b} -> predicate: (_: FStar.Seq.Base.seq a -> Type0) -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Prims.logical
let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s)
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 84, "start_col": 7, "start_line": 66 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel -> i: Prims.nat -> j: Prims.nat{i + j <= LowStar.Monotonic.Buffer.length b} -> predicate: (_: FStar.Seq.Base.seq a -> Type0) -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Prims.logical
Prims.GTot
[ "sometrivial" ]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "LowStar.Monotonic.Buffer.length", "FStar.Seq.Base.seq", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "FStar.Seq.Base.length", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "Prims.logical" ]
[]
false
false
false
false
true
let store_pre (#a: Type) (#rrel #rel: MB.srel a) (b: MB.mbuffer a rrel rel) (i: nat) (j: nat{i + j <= MB.length b}) (predicate: (Seq.seq a -> Type0)) =
fun (h: HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s: Seq.seq a). (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s)
false
LowStar.Endianness.fst
LowStar.Endianness.store32_le
val store32_le (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z))
val store32_le (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z))
let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 308, "start_col": 0, "start_line": 300 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 4} -> z: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowStar.Endianness.store32_le_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v" ]
[]
false
true
false
false
false
let store32_le (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) =
store32_le_i b 0ul z
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.bytes32
val bytes32 : t: Type0{Prims.hasEq t}
let bytes32 = B32.bytes
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 23, "end_line": 7, "start_col": 0, "start_line": 7 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Type0{Prims.hasEq t}
Prims.Tot
[ "total" ]
[]
[ "FStar.Bytes.bytes" ]
[]
false
false
false
false
false
let bytes32 =
B32.bytes
false
LowStar.Endianness.fst
LowStar.Endianness.load32_be
val load32_be (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z))
val load32_be (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z))
let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 337, "start_col": 0, "start_line": 330 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 4} -> FStar.HyperStack.ST.Stack FStar.UInt32.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load32_be_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u32", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v" ]
[]
false
true
false
false
false
let load32_be (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) =
load32_be_i b 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.store32_be
val store32_be (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z))
val store32_be (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z))
let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 328, "start_col": 0, "start_line": 320 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 4} -> z: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowStar.Endianness.store32_be_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v" ]
[]
false
true
false
false
false
let store32_be (b: B.buffer UInt8.t {B.length b == 4}) (z: UInt32.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) =
store32_be_i b 0ul z
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.alloca
val alloca: alloca_st (|Blake2S, M32|)
val alloca: alloca_st (|Blake2S, M32|)
let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 22, "start_col": 0, "start_line": 15 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.alloca_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Prims._assert", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "Hacl.Hash.Definitions.state", "Prims.Mkdtuple2", "Spec.Hash.Definitions.hash_alg", "Hacl.Hash.Definitions.m_spec", "Spec.Hash.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Blake2s_32.init", "FStar.UInt32.__uint_to_t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Hacl.Impl.Blake2.Core.element_t", "Spec.Blake2.Definitions.Blake2S", "Lib.IntTypes.mul_mod", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.Impl.Blake2.Core.row_len", "Hacl.Impl.Blake2.Core.alloc_state", "Hacl.Impl.Blake2.Core.state_p" ]
[]
false
false
false
false
false
let alloca () =
let h0 = ST.get () in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s
false
LowStar.Endianness.fst
LowStar.Endianness.store128_le
val store128_le (b: B.buffer UInt8.t {B.length b == 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z))
val store128_le (b: B.buffer UInt8.t {B.length b == 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z))
let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 397, "start_col": 0, "start_line": 389 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 16} -> z: FStar.UInt128.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt128.t", "LowStar.Endianness.store128_le_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt128.n", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt128.v" ]
[]
false
true
false
false
false
let store128_le (b: B.buffer UInt8.t {B.length b == 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) =
store128_le_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.load64_be
val load64_be (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z))
val load64_be (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z))
let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 367, "start_col": 0, "start_line": 360 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 8} -> FStar.HyperStack.ST.Stack FStar.UInt64.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load64_be_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u64", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt64.v" ]
[]
false
true
false
false
false
let load64_be (b: B.buffer UInt8.t {B.length b == 8}) : Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) =
load64_be_i b 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.store64_le
val store64_le (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z))
val store64_le (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z))
let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 348, "start_col": 0, "start_line": 340 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 8} -> z: FStar.UInt64.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt64.t", "LowStar.Endianness.store64_le_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt64.v" ]
[]
false
true
false
false
false
let store64_le (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) =
store64_le_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.store64_be
val store64_be (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z))
val store64_be (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z))
let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 377, "start_col": 0, "start_line": 369 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 8} -> z: FStar.UInt64.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt64.t", "LowStar.Endianness.store64_be_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt64.v" ]
[]
false
true
false
false
false
let store64_be (b: B.buffer UInt8.t {B.length b == 8}) (z: UInt64.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) =
store64_be_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.store16_be
val store16_be (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z))
val store16_be (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z))
let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 288, "start_col": 0, "start_line": 280 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 2} -> z: FStar.UInt16.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt16.t", "LowStar.Endianness.store16_be_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt16.n", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt16.v" ]
[]
false
true
false
false
false
let store16_be (b: B.buffer UInt8.t {B.length b == 2}) (z: UInt16.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) =
store16_be_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.load128_be
val load128_be (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z))
val load128_be (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z))
let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 407, "start_col": 0, "start_line": 400 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 16} -> FStar.HyperStack.ST.Stack FStar.UInt128.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load128_be_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u128", "FStar.UInt128.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt128.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt128.v" ]
[]
false
true
false
false
false
let load128_be (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) =
load128_be_i b 0ul
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.finish
val finish: finish_st (|Blake2S, M32|)
val finish: finish_st (|Blake2S, M32|)
let finish s dst = BlS32.finish (hash_len Blake2S) dst s
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 38, "start_col": 0, "start_line": 38 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s let init s = BlS32.init s 0ul 32ul let update_multi s ev blocks n = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_multi #(n `FStar.UInt32.mul` block_len Blake2S) wv s (secret ev) blocks n; ST.pop_frame () let update_last s prev input input_len = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_last #input_len wv s (secret prev) input_len input; ST.pop_frame()
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.finish_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Hash.Definitions.state", "Prims.Mkdtuple2", "Spec.Hash.Definitions.hash_alg", "Hacl.Hash.Definitions.m_spec", "Spec.Hash.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Hash.Definitions.hash_t", "Hacl.Hash.Definitions.get_alg", "Hacl.Blake2s_32.finish", "Hacl.Hash.Definitions.hash_len", "Prims.unit" ]
[]
false
false
false
false
false
let finish s dst =
BlS32.finish (hash_len Blake2S) dst s
false
LowStar.Endianness.fst
LowStar.Endianness.load32_le
val load32_le (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z))
val load32_le (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z))
let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 317, "start_col": 0, "start_line": 310 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 4} -> FStar.HyperStack.ST.Stack FStar.UInt32.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load32_le_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u32", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt32.v" ]
[]
false
true
false
false
false
let load32_le (b: B.buffer UInt8.t {B.length b == 4}) : Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) =
load32_le_i b 0ul
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.update_multi
val update_multi: update_multi_st (|Blake2S, M32|)
val update_multi: update_multi_st (|Blake2S, M32|)
let update_multi s ev blocks n = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_multi #(n `FStar.UInt32.mul` block_len Blake2S) wv s (secret ev) blocks n; ST.pop_frame ()
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 30, "start_col": 0, "start_line": 26 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s let init s = BlS32.init s 0ul 32ul
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.update_multi_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Hash.Definitions.state", "Prims.Mkdtuple2", "Spec.Hash.Definitions.hash_alg", "Hacl.Hash.Definitions.m_spec", "Spec.Hash.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Hash.Definitions.extra_state", "Hacl.Hash.Definitions.get_alg", "Hacl.Hash.Definitions.blocks_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "LowStar.Monotonic.Buffer.length", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "FStar.Mul.op_Star", "Spec.Hash.Definitions.block_length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Blake2s_32.update_multi", "FStar.UInt32.mul", "Hacl.Hash.Definitions.block_len", "Lib.IntTypes.secret", "Spec.Blake2.Definitions.limb_inttype", "Spec.Blake2.Definitions.Blake2S", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Hacl.Impl.Blake2.Core.element_t", "Lib.IntTypes.mul_mod", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.Impl.Blake2.Core.row_len", "Hacl.Impl.Blake2.Core.alloc_state", "Hacl.Impl.Blake2.Core.state_p", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
false
false
let update_multi s ev blocks n =
ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_multi #(n `FStar.UInt32.mul` (block_len Blake2S)) wv s (secret ev) blocks n; ST.pop_frame ()
false
LowStar.Endianness.fst
LowStar.Endianness.index_64_be
val index_64_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_be (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i))
val index_64_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_be (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i))
let index_64_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_be (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i)) = load64_be_i b FStar.UInt32.(8ul *^ i)
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 465, "start_col": 0, "start_line": 455 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul let store128_be (b:B.buffer UInt8.t{B.length b = 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_be_i b 0ul z /// Index and update /// ---------------- /// /// These are more sophisticated than load/store above, because they reason /// over the underlying sequence of bytes interpreted as a sequence of (little|big)-endian /// integers. #set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0" inline_for_extraction let index_32_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_be_i b FStar.UInt32.(4ul *^ i) inline_for_extraction let index_32_le (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_le_i b FStar.UInt32.(4ul *^ i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer LowStar.Endianness.u8 rrel rel -> i: LowStar.Endianness.u32 -> FStar.HyperStack.ST.Stack LowStar.Endianness.u64
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Endianness.u8", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Endianness.u32", "LowStar.Endianness.load64_be_i", "FStar.UInt32.op_Star_Hat", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u64", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowStar.Monotonic.Buffer.length", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_Division", "Prims.eq2", "FStar.UInt64.t", "FStar.Seq.Base.index", "FStar.Endianness.seq_uint64_of_be", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
true
false
false
false
let index_64_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_be (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i)) =
load64_be_i b FStar.UInt32.(8ul *^ i)
false
LowStar.Endianness.fst
LowStar.Endianness.load16_le
val load16_le (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z))
val load16_le (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z))
let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 277, "start_col": 0, "start_line": 270 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 2} -> FStar.HyperStack.ST.Stack FStar.UInt16.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load16_le_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u16", "FStar.UInt16.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt16.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt16.v" ]
[]
false
true
false
false
false
let load16_le (b: B.buffer UInt8.t {B.length b == 2}) : Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) =
load16_le_i b 0ul
false
Vale.Math.Poly2.Galois.fst
Vale.Math.Poly2.Galois.lemma_smul_gmul_rec
val lemma_smul_gmul_rec (f: G.field) (e1 e2: G.felem f) (n: nat) : Lemma (let p, a, b = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n)
val lemma_smul_gmul_rec (f: G.field) (e1 e2: G.felem f) (n: nat) : Lemma (let p, a, b = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n)
let rec lemma_smul_gmul_rec (f:G.field) (e1 e2:G.felem f) (n:nat) : Lemma ( let (p, a, b) = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) = let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then ( lemma_smul_gmul_rec f e1 e2 (n - 1); let (sp, sa, sb) = smul_rec a b m (n - 1) in let (gp, ga, gb) = gmul_rec f e1 e2 (n - 1) in //assert (to_poly gp == sp); //assert (to_poly ga == sa); //assert (to_poly gb == sb); let sp' = sp +. (if sb.[0] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in // mod_bit1 is equivalent to mod in this case let sb' = shift sb (-1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[k - 1] then m_lo else zero in let ssa' = ssa +. ssa_add in //assert (sa' == ssa'); let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[0] then lemma_equal (sb &. one) one; //assert (sb.[0] <==> I.v (I.logand gb (G.one #f)) = I.v (G.one #f)); lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); //assert (to_poly gp' == sp'); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; //assert (to_poly f.G.irred == m_lo); lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); //assert (to_poly carry_irred == ssa_add); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); //assert (to_poly ga_shift == ssa); //assert (to_poly ga' == ssa'); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); //assert (to_poly gb' == sb'); () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 529, "start_col": 0, "start_line": 464 }
module Vale.Math.Poly2.Galois open FStar.Mul module U = FStar.UInt module PL = Vale.Math.Poly2.Lemmas module D = Vale.Math.Poly2.Defs_s //module PD = Vale.Math.Poly2.Defs module GI = Vale.Math.Poly2.Galois.IntTypes // recursive definitions of from_vec/to_vec are prone to matching loops, so use no fuel from here on #reset-options "--max_fuel 0 --max_ifuel 0" let to_poly #f e = let G.GF t irred = f in let n = I.bits t in reverse (of_seq (U.to_vec #n (I.v e))) (n - 1) let to_felem f p = let G.GF t irred = f in let n = I.bits t in let p = reverse p (n - 1) in Lib.IntTypes.Compatibility.nat_to_uint (U.from_vec #n (to_seq p n)) let lemma_to_poly_degree #f e = reveal_defs () let lemma_irred_degree f = let G.GF t irred = f in let n = I.bits t in PL.lemma_index_all (); PL.lemma_monomial_define n; PL.lemma_add_define_all (); PL.lemma_degree_is (irred_poly f) n; () let lemma_poly_felem f p = let G.GF t irred = f in let n = I.bits t in let r = reverse p (n - 1) in let s = to_seq r n in let u = U.from_vec #n s in let e = Lib.IntTypes.Compatibility.nat_to_uint u in let u' = I.v #t #I.SEC e in let s' = U.to_vec #n u' in let r' = of_seq s' in let p' = reverse r' (n - 1) in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; lemma_equal p p'; () let lemma_felem_poly #f e = let G.GF t irred = f in let n = I.bits t in let u = I.v #t #I.SEC e in let s = U.to_vec #n u in let r = of_seq s in let p = reverse r (n - 1) in let r' = reverse p (n - 1) in let s' = to_seq r' n in let u' = U.from_vec #n s' in let e' = Lib.IntTypes.Compatibility.nat_to_uint #t #I.SEC u' in PL.lemma_index_all (); PL.lemma_reverse_define_all (); lemma_equal r r'; assert (equal s s'); Lib.IntTypes.Compatibility.uintv_extensionality e e'; () let lemma_zero f = let G.GF t irred = f in let n = I.bits t in let a = zero in let b = to_poly #f G.zero in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_zero_define (); (if 0 <= i && i < n then U.zero_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i //let lemma_zero' (f:G.field) : Lemma // (G.zero == to_felem f zero) // = // lemma_zero f; // lemma_felem_poly #f G.zero let lemma_one f = let G.GF t irred = f in let n = I.bits t in let a = one in let b = to_poly #f G.one in let eq_i (i:int) : Lemma (a.[i] == b.[i]) = PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_one_define (); (if 0 <= i && i < n then U.one_to_vec_lemma #n (n - 1 - i)); () in PL.lemma_pointwise_equal a b eq_i let lemma_add f e1 e2 = let G.GF t irred = f in GI.define_logxor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_add_define_all (); lemma_equal (to_poly (G.fadd e1 e2)) (to_poly e1 +. to_poly e2) let lemma_and f e1 e2 = let G.GF t irred = f in GI.define_logand t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_and_define_all (); lemma_equal (to_poly (I.logand e1 e2)) (to_poly e1 &. to_poly e2) let lemma_or f e1 e2 = let G.GF t irred = f in GI.define_logor t e1 e2; PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_or_define_all (); lemma_equal (to_poly (I.logor e1 e2)) (to_poly e1 |. to_poly e2) let lemma_shift_left f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); PL.lemma_mod_monomial (shift (to_poly e) (I.uint_v n)) nf; assert (I.uint_v (I.shift_left e n) == U.shift_left #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_left e n)) (shift (to_poly e) (I.uint_v n) %. monomial (I.bits f.G.t)) let lemma_shift_right f e n = let G.GF t irred = f in let nf = I.bits t in PL.lemma_index_all (); PL.lemma_reverse_define_all (); PL.lemma_shift_define_all (); assert (I.uint_v (I.shift_right e n) == U.shift_right #nf (I.uint_v e) (I.uint_v n)); lemma_equal (to_poly (I.shift_right e n)) (shift (to_poly e) (-(I.uint_v n))) #reset-options (* Various definitions of multiply, ranging from Poly2 definition to GaloisField definition: - Vale.Math.Poly2.Defs_s.mul - mul_def: same as Defs_s.mul, but using abstract definition of poly - pmul: equivalent to mul_def, but defined recursively based on adds and shifts by n - mmul: same as pmul, but also do a "mod m" in the add - smul: same as mmul, but incrementally shift by 1 rather than shifting by n and implement "mod m" using add - gmul: same as fmul, but defined using recursion instead of repeati - fmul: same as Spec.GaloisField.fmul, but use named function instead of lambda - Spec.GaloisField.fmul *) let poly_length (p:poly) : nat = (if degree p < 0 then PL.lemma_degree_negative p); 1 + degree p unfold let sum_of_bools = D.sum_of_bools let mul_element_fun (a b:poly) (k i:int) : bool = a.[i] && b.[k - i] let mul_element (a b:poly) (k:int) : bool = sum_of_bools 0 (k + 1) (mul_element_fun a b k) [@"opaque_to_smt"] let mul_def (a b:poly) : Pure poly (requires True) (ensures fun p -> let len = poly_length a + poly_length b in poly_length p <= len /\ (forall (i:nat).{:pattern p.[i]} i < len ==> p.[i] == mul_element a b i) ) = let len = poly_length a + poly_length b in of_fun len (fun (i:nat) -> mul_element a b i) let rec pmul_rec (a b:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = pmul_rec a b n' in if b.[n'] then p +. shift a n' else p let pmul (a b:poly) : poly = pmul_rec a b (poly_length b) let rec mmul (a b m:poly) (n:nat) : Tot poly (decreases n) = if n = 0 then zero else let n' = n - 1 in let p = mmul a b m n' in if b.[n'] then p +. (shift a n' %. m) else p let mod_bit1 (a m:poly) : poly = if a.[degree m] then a +. m else a let rec smul_rec (a b m:poly) (n:nat) : Tot (poly & poly & poly) (decreases n) = if n = 0 then (zero, a, b) else let (p, a, b) = smul_rec a b m (n - 1) in let p = p +. (if b.[0] then a else zero) in let a = mod_bit1 (shift a 1) m in // mod_bit1 is equivalent to mod in this case let b = shift b (-1) in (p, a, b) let smul (a b m:poly) (n:nat) : poly = let (p, _, _) = smul_rec a b m n in p let mod_shift1 (a irred:poly) (k:nat) : poly = let s = shift a 1 %. monomial k in s +. (if a.[k - 1] then irred else zero) let fmul_t (f:G.field) = G.felem f & G.felem f & G.felem f let fmul_iter (f:G.field) : i:nat{i < I.bits f.G.t - 1} -> fmul_t f -> fmul_t f = fun i (p, a, b) -> let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in let carry_mask = I.eq_mask #f.G.t (I.shift_right a (I.size (I.bits f.G.t - 1))) (G.one #f) in let a = I.shift_left a (I.size 1) in let a = I.logxor a (I.logand carry_mask f.G.irred) in let b = I.shift_right b (I.size 1) in (p, a, b) let rec gmul_rec (f:G.field) (a b:G.felem f) (n:nat) : fmul_t f = if n = 0 then (G.zero #f, a, b) else let (p, a, b) = gmul_rec f a b (n - 1) in fmul_iter f 0 (p, a, b) let gmul (f:G.field) (a b:G.felem f) : G.felem f = let (p, _, _) = gmul_rec f a b (I.bits f.G.t) in p let fmul (f:G.field) (a b:G.felem f) : G.felem f = let one = G.one #f in let zero = G.zero #f in let (p, a, b) = Lib.LoopCombinators.repeati (I.bits f.G.t - 1) (fmul_iter f) (zero, a, b) in let b0 = I.eq_mask #f.G.t (I.logand b (G.one #f)) (G.one #f) in let p = I.logxor p (I.logand b0 a) in p (* Lemmas about multiplication *) let d (a:poly) : (b:D.poly{poly == D.poly /\ coerce D.poly a == b}) = reveal_defs (); Vale.Math.Poly2_s.to_poly a let rec lemma_mul_element_rec (a b:poly) (k:int) (n:int) : Lemma (sum_of_bools 0 n (mul_element_fun a b k) == sum_of_bools 0 n (D.mul_element_fun (d a) (d b) k)) = reveal_defs (); if n > 0 then lemma_mul_element_rec a b k (n - 1) let lemma_mul_element (a b:poly) (k:int) : Lemma (mul_element a b k == D.mul_element (d a) (d b) k) = reveal_defs (); lemma_mul_element_rec a b k (k + 1); () let lemma_mul_def (a b:poly) : Lemma (mul_def a b == mul a b) = reveal_defs (); PL.lemma_pointwise_equal (mul_def a b) (mul a b) (lemma_mul_element a b) let rec lemma_pmul_degree (a b:poly) (n:nat) : Lemma (requires True) (ensures poly_length (pmul_rec a b n) <= poly_length a + n) = if n > 0 then lemma_pmul_degree a b (n - 1) let rec lemma_mul_pmul_k_base (a b:poly) (k:int) (n:nat) : Lemma (requires True) (ensures sum_of_bools 0 n (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n) = PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); if n > 0 then lemma_mul_pmul_k_base a b k (n - 1) let rec lemma_mul_pmul_k_left (a b:poly) (k:int) (n:nat) (n':int) : Lemma (requires k + 1 <= n' /\ n' <= n) (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases (n - n')) = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n > n' then lemma_mul_pmul_k_left a b k n (n' + 1) else lemma_mul_pmul_k_base a b k n let rec lemma_mul_pmul_k_right (a b:poly) (k:int) (n n':nat) : Lemma (requires n == poly_length a /\ n <= n') (ensures sum_of_bools 0 n' (mul_element_fun a b k) == (pmul_rec b a n).[k]) (decreases n') = PL.lemma_index_all (); PL.lemma_shift_define_all (); if n' > n then lemma_mul_pmul_k_right a b k n (n' - 1) else lemma_mul_pmul_k_base a b k n let lemma_mul_pmul_k (a b:poly) (k:int) : Lemma ((mul_def a b).[k] == (pmul b a).[k]) = PL.lemma_index_all (); let n = poly_length a in lemma_pmul_degree b a n; if n = k + 1 then lemma_mul_pmul_k_base a b k n else if n > k + 1 then lemma_mul_pmul_k_left a b k n (k + 1) else lemma_mul_pmul_k_right a b k n (k + 1) let lemma_mul_pmul (a b:poly) : Lemma (mul_def a b == pmul b a) = PL.lemma_pointwise_equal (mul_def a b) (pmul b a) (lemma_mul_pmul_k a b) let rec lemma_mmul_pmul_rec (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0) (ensures mod (mmul a b m n) m == mod (pmul_rec a b n) m) = if n > 0 then ( let n' = n - 1 in let mp = mmul a b m n' in let pp = pmul_rec a b n' in lemma_mmul_pmul_rec a b m (n - 1); assert (mod mp m == mod pp m); let s = shift a n' in PL.lemma_mod_distribute pp s m; PL.lemma_mod_distribute mp s m; PL.lemma_mod_distribute mp (s %. m) m; PL.lemma_mod_mod s m; //assert ((mp +. (s %. m)) %. m == (mp +. s) %. m); //assert ((mp +. s) %. m == (pp +. s) %. m); //assert (mod (add mp (mod s m)) m == mod (add pp s) m); //assert (mod (add mp (mod (shift a n') m)) m == mod (add pp (shift a n')) m); () ) let rec lemma_mmul_pmul (a b m:poly) (n:nat) : Lemma (requires poly_length m > 0 /\ n >= poly_length b) (ensures mod (mmul a b m n) m == mod (pmul a b) m) = PL.lemma_index_all (); if n = poly_length b then lemma_mmul_pmul_rec a b m n else lemma_mmul_pmul a b m (n - 1) let lemma_mod_bit1 (a m:poly) : Lemma (requires poly_length a <= poly_length m /\ 0 <= degree m) (ensures mod_bit1 a m == a %. m) = PL.lemma_index_all (); PL.lemma_add_define_all (); let n = poly_length m in if (poly_length a < n) then PL.lemma_mod_small a m else ( lemma_degree a; lemma_degree m; lemma_degree (a +. m); PL.lemma_mod_distribute a m m; PL.lemma_mod_cancel m; lemma_add_zero (a %. m); //assert ((a +. m) %. m == a %. m); PL.lemma_mod_small (a +. m) m; () ) let lemma_mod_shift1 (a irred:poly) (k:nat) : Lemma (requires degree a < k /\ degree irred < k) (ensures mod_bit1 (shift a 1) (monomial k +. irred) == mod_shift1 a irred k /\ (shift a (1 - k) == one <==> a.[k - 1])) = let m = monomial k +. irred in let s = shift a 1 %. monomial k in PL.lemma_index_all (); PL.lemma_add_define_all (); PL.lemma_shift_define_all (); PL.lemma_monomial_define k; PL.lemma_one_define (); assert (m.[k]); PL.lemma_mod_monomial (shift a 1) k; if a.[k - 1] then ( lemma_equal s (shift a 1 +. monomial k); lemma_equal (shift a 1 +. m) (s +. irred); () ) else ( assert ((shift a (1 - k)).[0] == false); () ); lemma_equal (mod_bit1 (shift a 1) m) (mod_shift1 a irred k); if a.[k - 1] then lemma_equal (shift a (1 - k)) one; () let rec lemma_mmul_smul_rec (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul_rec a b m n == (mmul a b m n, shift a n %. m, shift b (-n)) /\ mmul a b m n == mmul a b m n %. m ) = PL.lemma_index_all (); PL.lemma_shift_define_all (); PL.lemma_mod_small a m; PL.lemma_mod_small zero m; lemma_equal (shift a 0) a; let (p0, a0, b0) = smul_rec a b m n in if n > 0 then ( let n1 = n - 1 in let (p1, a1, b1) = smul_rec a b m n1 in lemma_mmul_smul_rec a b m n1; PL.lemma_shift_shift b (-n1) (-1); PL.lemma_shift_shift a n1 1; PL.lemma_shift_mod (shift a n1) m 1; PL.lemma_mod_distribute p1 a1 m; PL.lemma_mod_mod (shift a n1) m; lemma_mod_bit1 (shift a1 1) m; //assert ((p1 +. a1) %. m == p1 %. m +. a1 %. m); //assert ((p1 +. a1) %. m == p1 %. m +. (shift a n1 %. m)); //assert ((p1 +. a1) %. m == p1 +. (shift a n1 %. m)); lemma_add_zero p1; () ); lemma_equal b0 (shift b (-n)); () let lemma_mmul_smul (a b m:poly) (n:nat) : Lemma (requires degree m >= 0 /\ degree a < degree m) (ensures smul a b m n == mmul a b m n) = lemma_mmul_smul_rec a b m n let lemma_eqmask_and (t:I.inttype{Lib.IntTypes.unsigned t}) (a b c:I.uint_t t I.SEC) : Lemma (requires t =!= Lib.IntTypes.U1) (ensures I.v (I.logand (I.eq_mask a b) c) == (if I.v a = I.v b then I.v c else 0)) = GI.define_eq_mask t a b; GI.define_logand t (I.eq_mask a b) c; U.logand_commutative #(I.bits t) (I.v (I.eq_mask a b)) (I.v c); U.logand_lemma_1 #(I.bits t) (I.v c); U.logand_lemma_2 #(I.bits t) (I.v c); ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Galois.IntTypes.fsti.checked", "Vale.Math.Poly2.Defs_s.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.Compatibility.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Vale.Math.Poly2.Galois.fst" }
[ { "abbrev": true, "full_module": "Vale.Math.Poly2.Galois.IntTypes", "short_module": "GI" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": "D" }, { "abbrev": true, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": "PL" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.Math.Poly2_s", "short_module": "P" }, { "abbrev": true, "full_module": "Spec.GaloisField", "short_module": "G" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 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" }
false
f: Spec.GaloisField.field -> e1: Spec.GaloisField.felem f -> e2: Spec.GaloisField.felem f -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures (let _ = Vale.Math.Poly2.Galois.gmul_rec f e1 e2 n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ p a b = _ in (Vale.Math.Poly2.Galois.to_poly p, Vale.Math.Poly2.Galois.to_poly a, Vale.Math.Poly2.Galois.to_poly b) == Vale.Math.Poly2.Galois.smul_rec (Vale.Math.Poly2.Galois.to_poly e1) (Vale.Math.Poly2.Galois.to_poly e2) (Vale.Math.Poly2.Galois.irred_poly f) n) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.GaloisField.field", "Spec.GaloisField.felem", "Prims.nat", "Lib.IntTypes.inttype", "Prims.l_and", "Prims.b2t", "Lib.IntTypes.unsigned", "Prims.op_disEquality", "Lib.IntTypes.U1", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.op_GreaterThan", "Vale.Math.Poly2_s.poly", "Prims.unit", "Vale.Math.Poly2.Galois.lemma_shift_right", "Lib.IntTypes.uint", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.int_t", "Spec.GaloisField.__proj__GF__item__t", "Lib.IntTypes.shift_right", "Lib.IntTypes.size", "Vale.Math.Poly2.Galois.lemma_shift_left", "Vale.Math.Poly2.Galois.lemma_add", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Vale.Math.Poly2.Galois.lemma_felem_poly", "Vale.Math.Poly2.Galois.lemma_eqmask_and", "Spec.GaloisField.one", "Spec.GaloisField.__proj__GF__item__irred", "Lib.IntTypes.logand", "Vale.Math.Poly2_s.op_String_Access", "Vale.Math.Poly2.lemma_equal", "Vale.Math.Poly2.Galois.op_Amp_Dot", "Vale.Math.Poly2_s.one", "Prims.bool", "Vale.Math.Poly2.Lemmas.lemma_and_define_all", "Vale.Math.Poly2.Lemmas.lemma_one_define", "Vale.Math.Poly2.Galois.lemma_and", "Lib.IntTypes.logxor", "Lib.IntTypes.shift_left", "Lib.IntTypes.eq_mask", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2_s.zero", "Vale.Math.Poly2.op_Percent_Dot", "Vale.Math.Poly2_s.shift", "Vale.Math.Poly2_s.monomial", "Vale.Math.Poly2.Galois.lemma_mod_shift1", "Vale.Math.Poly2.Galois.to_poly", "Prims.int", "Prims.op_Minus", "Vale.Math.Poly2.Galois.mod_bit1", "Vale.Math.Poly2.Galois.fmul_t", "Vale.Math.Poly2.Galois.gmul_rec", "FStar.Pervasives.Native.tuple3", "Vale.Math.Poly2.Galois.smul_rec", "Vale.Math.Poly2.Galois.lemma_smul_gmul_rec", "Vale.Math.Poly2.Galois.lemma_one", "Vale.Math.Poly2.Galois.lemma_zero", "Vale.Math.Poly2.Galois.irred_poly", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.Mktuple3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_smul_gmul_rec (f: G.field) (e1 e2: G.felem f) (n: nat) : Lemma (let p, a, b = gmul_rec f e1 e2 n in (to_poly p, to_poly a, to_poly b) == smul_rec (to_poly e1) (to_poly e2) (irred_poly f) n) =
let G.GF t irred = f in let a = to_poly e1 in let b = to_poly e2 in let m = irred_poly f in lemma_zero f; lemma_one f; if n > 0 then (lemma_smul_gmul_rec f e1 e2 (n - 1); let sp, sa, sb = smul_rec a b m (n - 1) in let gp, ga, gb = gmul_rec f e1 e2 (n - 1) in let sp' = sp +. (if sb.[ 0 ] then sa else zero) in let sa' = mod_bit1 (shift sa 1) m in let sb' = shift sb (- 1) in let k = I.bits t in let m_lo = to_poly #f irred in lemma_mod_shift1 sa m_lo k; let ssa = shift sa 1 %. monomial k in let ssa_add = if sa.[ k - 1 ] then m_lo else zero in let ssa' = ssa +. ssa_add in let gb0 = I.eq_mask #f.G.t (I.logand gb (G.one #f)) (G.one #f) in let gp' = I.logxor gp (I.logand gb0 ga) in let carry_mask = I.eq_mask #f.G.t (I.shift_right ga (I.size (I.bits f.G.t - 1))) (G.one #f) in let ga_shift = I.shift_left ga (I.size 1) in let carry_irred = I.logand carry_mask f.G.irred in let ga' = I.logxor ga_shift carry_irred in lemma_and f gb (G.one #f); lemma_felem_poly #f (I.logand gb (G.one #f)); lemma_felem_poly #f G.one; PL.lemma_one_define (); PL.lemma_and_define_all (); if sb.[ 0 ] then lemma_equal (sb &. one) one; lemma_eqmask_and t (I.logand gb (G.one #f)) (G.one #f) ga; lemma_add f gp (I.logand gb0 ga); let right_mask = I.shift_right ga (I.size (I.bits f.G.t - 1)) in lemma_eqmask_and t right_mask (G.one #f) f.G.irred; lemma_felem_poly right_mask; lemma_shift_right f ga (I.size (I.bits f.G.t - 1)); lemma_add f ga_shift carry_irred; lemma_shift_left f ga (I.uint #I.U32 #I.PUB 1); let gb' = I.shift_right gb (I.size 1) in lemma_shift_right f gb (I.uint 1); ())
false
LowStar.Endianness.fst
LowStar.Endianness.load128_le
val load128_le (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z))
val load128_le (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z))
let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 387, "start_col": 0, "start_line": 380 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b == 16} -> FStar.HyperStack.ST.Stack FStar.UInt128.t
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.eq2", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "LowStar.Endianness.load128_le_i", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u128", "FStar.UInt128.t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "Prims.l_or", "FStar.UInt.size", "FStar.UInt128.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Endianness.le_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt128.v" ]
[]
false
true
false
false
false
let load128_le (b: B.buffer UInt8.t {B.length b == 16}) : Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) =
load128_le_i b 0ul
false
LowStar.Endianness.fst
LowStar.Endianness.index_32_le
val index_32_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i))
val index_32_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i))
let index_32_le (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_le_i b FStar.UInt32.(4ul *^ i)
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 452, "start_col": 0, "start_line": 442 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul let store128_be (b:B.buffer UInt8.t{B.length b = 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_be_i b 0ul z /// Index and update /// ---------------- /// /// These are more sophisticated than load/store above, because they reason /// over the underlying sequence of bytes interpreted as a sequence of (little|big)-endian /// integers. #set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0" inline_for_extraction let index_32_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_be_i b FStar.UInt32.(4ul *^ i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer LowStar.Endianness.u8 rrel rel -> i: LowStar.Endianness.u32 -> FStar.HyperStack.ST.Stack LowStar.Endianness.u32
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Endianness.u8", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Endianness.u32", "LowStar.Endianness.load32_le_i", "FStar.UInt32.op_Star_Hat", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowStar.Monotonic.Buffer.length", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_Division", "Prims.eq2", "FStar.UInt32.t", "FStar.Seq.Base.index", "FStar.Endianness.seq_uint32_of_le", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
true
false
false
false
let index_32_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) =
load32_le_i b FStar.UInt32.(4ul *^ i)
false
LowStar.Endianness.fst
LowStar.Endianness.store128_be
val store128_be (b: B.buffer UInt8.t {B.length b = 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z))
val store128_be (b: B.buffer UInt8.t {B.length b = 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z))
let store128_be (b:B.buffer UInt8.t{B.length b = 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_be_i b 0ul z
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 417, "start_col": 0, "start_line": 409 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer FStar.UInt8.t {LowStar.Monotonic.Buffer.length b = 16} -> z: FStar.UInt128.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt128.t", "LowStar.Endianness.store128_be_i", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.eq2", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt128.n", "FStar.Endianness.be_to_n", "LowStar.Monotonic.Buffer.as_seq", "FStar.UInt128.v" ]
[]
false
true
false
false
false
let store128_be (b: B.buffer UInt8.t {B.length b = 16}) (z: UInt128.t) : Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) =
store128_be_i b 0ul z
false
LowStar.Endianness.fst
LowStar.Endianness.index_32_be
val index_32_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i))
val index_32_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i))
let index_32_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_be_i b FStar.UInt32.(4ul *^ i)
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 439, "start_col": 0, "start_line": 429 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul let store128_be (b:B.buffer UInt8.t{B.length b = 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_be_i b 0ul z /// Index and update /// ---------------- /// /// These are more sophisticated than load/store above, because they reason /// over the underlying sequence of bytes interpreted as a sequence of (little|big)-endian /// integers. #set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer LowStar.Endianness.u8 rrel rel -> i: LowStar.Endianness.u32 -> FStar.HyperStack.ST.Stack LowStar.Endianness.u32
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Endianness.u8", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Endianness.u32", "LowStar.Endianness.load32_be_i", "FStar.UInt32.op_Star_Hat", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowStar.Monotonic.Buffer.length", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_Division", "Prims.eq2", "FStar.UInt32.t", "FStar.Seq.Base.index", "FStar.Endianness.seq_uint32_of_be", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
true
false
false
false
let index_32_be (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) =
load32_be_i b FStar.UInt32.(4ul *^ i)
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.serializer32_correct
val serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0
val serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0
let serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 = B32.reveal res == s input
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 27, "end_line": 108, "start_col": 0, "start_line": 100 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = () inline_for_extraction let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } ))) inline_for_extraction let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit { t2 == t1 } ) : Tot (parser32 (coerce_parser t2 p)) = p32 let validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (consumed) -> Some? gp /\ ( let (Some (_ , consumed')) = gp in U32.v consumed == (consumed' <: nat) ) let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option U32.t { validator_correct p input res } )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: LowParse.Spec.Base.serializer p -> input: t -> res: LowParse.SLow.Base.bytes32 -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.bytes32", "Prims.eq2", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "FStar.Bytes.reveal" ]
[]
false
false
false
false
true
let serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 =
B32.reveal res == s input
false
LowStar.Endianness.fst
LowStar.Endianness.index_64_le
val index_64_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_le (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i))
val index_64_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_le (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i))
let index_64_le (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_le (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i)) = load64_le_i b FStar.UInt32.(8ul *^ i)
{ "file_name": "ulib/LowStar.Endianness.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 478, "start_col": 0, "start_line": 468 }
module LowStar.Endianness /// Stateful operations between machine integers and buffers of uint8s. Most of /// these operations are implemented natively using the target's system endianness /// headers, relying on macros or static inline declarations. /// /// .. note:: /// /// This module supersedes ``C.Endianness``. module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Endianness open LowStar.BufferOps module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U128 = FStar.UInt128 module HS = FStar.HyperStack inline_for_extraction type u8 = U8.t inline_for_extraction type u16 = U16.t inline_for_extraction type u32 = U32.t inline_for_extraction type u64 = U64.t inline_for_extraction type u128 = U128.t /// Byte-swapping operations /// ------------------------ /// /// TODO these are totally unspecified assume val htole16: u16 -> u16 assume val le16toh: u16 -> u16 assume val htole32: u32 -> u32 assume val le32toh: u32 -> u32 assume val htole64: u64 -> u64 assume val le64toh: u64 -> u64 assume val htobe16: u16 -> u16 assume val be16toh: u16 -> u16 assume val htobe32: u32 -> u32 assume val be32toh: u32 -> u32 assume val htobe64: u64 -> u64 assume val be64toh: u64 -> u64 /// Precondition for store functions /// /// Parametrized by the predicate that different store functions can pass accordingly /// /// Typically saying sequence contents are le_to_n or be_to_n etc. unfold let store_pre (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h:HS.mem) -> let sb = MB.as_seq h b in let len = MB.length b in MB.live h b /\ (forall (s:Seq.seq a). //monotonicity precondition that once the contents of the buffer //between [i, j) are replaced as per the predicate, the //preorder rel is satisfied (Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\ Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\ predicate (Seq.slice s i (i + j))) ==> rel sb s) /// Common postcondition unfold let store_post (#a:Type) (#rrel #rel:MB.srel a) (b:MB.mbuffer a rrel rel) (i:nat) (j:nat{i + j <= MB.length b}) (predicate:Seq.seq a -> Type0) = fun (h0:HS.mem) (_:unit) (h1:HS.mem) -> MB.live h1 b /\ MB.(modifies (loc_buffer b) h0 h1) /\ (let s1 = MB.as_seq h0 b in let s2 = MB.as_seq h1 b in let len = MB.length b in //the buffer only changes in the interval [i, j) as per the predicate Seq.equal (Seq.slice s2 0 i) (Seq.slice s1 0 i) /\ Seq.equal (Seq.slice s2 (i + j) len) (Seq.slice s1 (i + j) len) /\ predicate (Seq.slice s2 i (i + j))) /// Loads and stores /// ---------------- /// /// These are primitive assume val store16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> le_to_n s == U16.v z))) assume val load16_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) (z:u16) : Stack unit (requires (store_pre b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) (ensures (store_post b (U32.v i) 2 (fun s -> be_to_n s == U16.v z))) assume val load16_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 2 <= MB.length b}) : Stack u16 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 2)) == U16.v z) assume val store32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> le_to_n s == U32.v z))) assume val load32_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) (z:u32) : Stack unit (requires (store_pre b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) (ensures (store_post b (U32.v i) 4 (fun s -> be_to_n s == U32.v z))) assume val load32_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 4 <= MB.length b}) : Stack u32 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 4)) == U32.v z) assume val store64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> le_to_n s == U64.v z))) assume val load64_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) (z:u64) : Stack unit (requires (store_pre b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) (ensures (store_post b (U32.v i) 8 (fun s -> be_to_n s == U64.v z))) assume val load64_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 8 <= MB.length b}) : Stack u64 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 8)) == U64.v z) assume val store128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> le_to_n s == U128.v z))) assume val load128_le_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ le_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) assume val store128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) (z:u128) : Stack unit (requires (store_pre b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) (ensures (store_post b (U32.v i) 16 (fun s -> be_to_n s == U128.v z))) assume val load128_be_i (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32{U32.v i + 16 <= MB.length b}) : Stack u128 (requires fun h -> MB.live h b) (ensures fun h0 z h1 -> h0 == h1 /\ MB.live h1 b /\ be_to_n (Seq.slice (MB.as_seq h1 b) (U32.v i) (U32.v i + 16)) == U128.v z) /// Loads and stores, on buffers of the right size. /// ----------------------------------------------- /// /// There is bunch of legacy code that wants these operators that operate on buffers of exactly the right size. This is actually more restrictive than the version above, which operates on monotonic buffers, so we offer specialized operators. let store16_le (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_le_i b 0ul z let load16_le (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_le_i b 0ul let store16_be (b:B.buffer UInt8.t{B.length b == 2}) (z:UInt16.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = store16_be_i b 0ul z let load16_be (b:B.buffer UInt8.t{B.length b == 2}): Stack UInt16.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt16.v z)) = load16_be_i b 0ul let store32_le (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_le_i b 0ul z let load32_le (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_le_i b 0ul let store32_be (b:B.buffer UInt8.t{B.length b == 4}) (z:UInt32.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = store32_be_i b 0ul z let load32_be (b:B.buffer UInt8.t{B.length b == 4}): Stack UInt32.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt32.v z)) = load32_be_i b 0ul let store64_le (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_le_i b 0ul z let load64_le (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_le_i b 0ul let load64_be (b:B.buffer UInt8.t{B.length b == 8}): Stack UInt64.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = load64_be_i b 0ul let store64_be (b:B.buffer UInt8.t{B.length b == 8}) (z:UInt64.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt64.v z)) = store64_be_i b 0ul z let load128_le (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_le_i b 0ul let store128_le (b:B.buffer UInt8.t{B.length b == 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ le_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_le_i b 0ul z let load128_be (b:B.buffer UInt8.t{B.length b == 16}): Stack UInt128.t (requires (fun h -> B.live h b)) (ensures (fun h0 z h1 -> h0 == h1 /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = load128_be_i b 0ul let store128_be (b:B.buffer UInt8.t{B.length b = 16}) (z:UInt128.t): Stack unit (requires (fun h -> B.live h b)) (ensures (fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ B.live h1 b /\ be_to_n (B.as_seq h1 b) == UInt128.v z)) = store128_be_i b 0ul z /// Index and update /// ---------------- /// /// These are more sophisticated than load/store above, because they reason /// over the underlying sequence of bytes interpreted as a sequence of (little|big)-endian /// integers. #set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0" inline_for_extraction let index_32_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_be (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_be_i b FStar.UInt32.(4ul *^ i) inline_for_extraction let index_32_le (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u32 (requires fun h -> MB.live h b /\ MB.length b % 4 = 0 /\ U32.v i < MB.length b / 4) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint32_of_le (MB.length b / 4) (MB.as_seq h0 b)) (U32.v i)) = load32_le_i b FStar.UInt32.(4ul *^ i) inline_for_extraction let index_64_be (#rrel #rel:MB.srel u8) (b:MB.mbuffer u8 rrel rel) (i:u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_be (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i)) = load64_be_i b FStar.UInt32.(8ul *^ i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowStar.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt128", "short_module": "U128" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Monotonic.Buffer.mbuffer LowStar.Endianness.u8 rrel rel -> i: LowStar.Endianness.u32 -> FStar.HyperStack.ST.Stack LowStar.Endianness.u64
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Endianness.u8", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Endianness.u32", "LowStar.Endianness.load64_le_i", "FStar.UInt32.op_Star_Hat", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u64", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowStar.Monotonic.Buffer.length", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_Division", "Prims.eq2", "FStar.UInt64.t", "FStar.Seq.Base.index", "FStar.Endianness.seq_uint64_of_le", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
true
false
false
false
let index_64_le (#rrel #rel: MB.srel u8) (b: MB.mbuffer u8 rrel rel) (i: u32) : Stack u64 (requires fun h -> MB.live h b /\ MB.length b % 8 = 0 /\ U32.v i < MB.length b / 8) (ensures fun h0 r h1 -> h0 == h1 /\ r = Seq.index (seq_uint64_of_le (MB.length b / 8) (MB.as_seq h0 b)) (UInt32.v i)) =
load64_le_i b FStar.UInt32.(8ul *^ i)
false
Hacl.Hash.Blake2s_32.fst
Hacl.Hash.Blake2s_32.update_last
val update_last: update_last_st (|Blake2S, M32|)
val update_last: update_last_st (|Blake2S, M32|)
let update_last s prev input input_len = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_last #input_len wv s (secret prev) input_len input; ST.pop_frame()
{ "file_name": "code/hash/Hacl.Hash.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 36, "start_col": 0, "start_line": 32 }
module Hacl.Hash.Blake2s_32 module B = LowStar.Buffer module ST = FStar.HyperStack.ST module BlS32 = Hacl.Blake2s_32 open Lib.IntTypes open Lib.Buffer #push-options "--fuel 0 --ifuel 0 --z3rlimit 20" friend Spec.Agile.Hash let malloc = BlS32.malloc_with_key let alloca () = let h0 = ST.get() in let s = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.init s 0ul 32ul; let h1 = ST.get () in B.modifies_only_not_unused_in (B.loc_none) h0 h1; assert (B.modifies B.loc_none h0 h1); s let init s = BlS32.init s 0ul 32ul let update_multi s ev blocks n = ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_multi #(n `FStar.UInt32.mul` block_len Blake2S) wv s (secret ev) blocks n; ST.pop_frame ()
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Blake2s_32.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "Hacl.Blake2s_32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Hash.Blake2s_32.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Blake2s_32", "short_module": "BlS32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2.Core", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Hash.Definitions.update_last_st (| Spec.Hash.Definitions.Blake2S, Hacl.Impl.Blake2.Core.M32 |)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Hash.Definitions.state", "Prims.Mkdtuple2", "Spec.Hash.Definitions.hash_alg", "Hacl.Hash.Definitions.m_spec", "Spec.Hash.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Hash.Definitions.prev_len_t", "Hacl.Hash.Definitions.get_alg", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Prims.l_and", "Spec.Hash.Definitions.is_keccak", "Prims.l_True", "Prims.bool", "Prims.b2t", "Spec.Hash.Definitions.less_than_max_input_length", "Prims.op_Addition", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Hash.Definitions.len_v", "Prims.logical", "Prims.op_LessThanOrEqual", "Spec.Hash.Definitions.block_length", "Lib.IntTypes.size_t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Blake2s_32.update_last", "Lib.IntTypes.secret", "Spec.Blake2.Definitions.limb_inttype", "Spec.Blake2.Definitions.Blake2S", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Hacl.Impl.Blake2.Core.element_t", "Lib.IntTypes.mul_mod", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Hacl.Impl.Blake2.Core.row_len", "Hacl.Impl.Blake2.Core.alloc_state", "Hacl.Impl.Blake2.Core.state_p", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
false
false
let update_last s prev input input_len =
ST.push_frame (); let wv = Hacl.Impl.Blake2.Core.alloc_state Spec.Blake2.Blake2S M32 in BlS32.update_last #input_len wv s (secret prev) input_len input; ST.pop_frame ()
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.serializer32_correct'
val serializer32_correct' (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0
val serializer32_correct' (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0
let serializer32_correct' (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 = B32.reveal res `bytes_equal` s input
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 38, "end_line": 118, "start_col": 0, "start_line": 110 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = () inline_for_extraction let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } ))) inline_for_extraction let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit { t2 == t1 } ) : Tot (parser32 (coerce_parser t2 p)) = p32 let validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (consumed) -> Some? gp /\ ( let (Some (_ , consumed')) = gp in U32.v consumed == (consumed' <: nat) ) let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option U32.t { validator_correct p input res } ) let serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 = B32.reveal res == s input
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: LowParse.Spec.Base.serializer p -> input: t -> res: LowParse.SLow.Base.bytes32 -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.bytes32", "LowParse.Bytes.bytes_equal", "FStar.Bytes.reveal" ]
[]
false
false
false
false
true
let serializer32_correct' (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 =
(B32.reveal res) `bytes_equal` (s input)
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.make_parser32
val make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32 -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res)))) : Tot (parser32 p)
val make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32 -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res)))) : Tot (parser32 p)
let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } )))
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 102, "end_line": 64, "start_col": 0, "start_line": 58 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> p32: (input: LowParse.SLow.Base.bytes32 -> Prims.Pure (FStar.Pervasives.Native.option (t * FStar.UInt32.t))) -> LowParse.SLow.Base.parser32 p
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.bytes32", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.t", "Prims.l_True", "LowParse.SLow.Base.parser32_correct", "LowParse.SLow.Base.parser32" ]
[]
false
false
false
false
false
let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32 -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res)))) : Tot (parser32 p) =
(fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) {parser32_correct p input res})))
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.parser32_correct
val parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0
val parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0
let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) )
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 24, "start_col": 0, "start_line": 9 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> input: LowParse.SLow.Base.bytes32 -> res: FStar.Pervasives.Native.option (t * FStar.UInt32.t) -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.bytes32", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.t", "Prims.eq2", "LowParse.Spec.Base.consumed_length", "FStar.Bytes.reveal", "FStar.Pervasives.Native.None", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt32.v", "Prims.nat", "Prims.logical", "LowParse.Spec.Base.parse" ]
[]
false
false
false
false
true
let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 =
let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ (let Some (hres', consumed') = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat))
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.coerce_parser32
val coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit{t2 == t1}) : Tot (parser32 (coerce_parser t2 p))
val coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit{t2 == t1}) : Tot (parser32 (coerce_parser t2 p))
let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit { t2 == t1 } ) : Tot (parser32 (coerce_parser t2 p)) = p32
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 75, "start_col": 0, "start_line": 67 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = () inline_for_extraction let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } )))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t2: Type -> p32: LowParse.SLow.Base.parser32 p -> u71: u72: Prims.unit{t2 == t1} -> LowParse.SLow.Base.parser32 (LowParse.Spec.Base.coerce_parser t2 p)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "Prims.unit", "Prims.eq2", "LowParse.Spec.Base.coerce_parser" ]
[]
false
false
false
false
false
let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit{t2 == t1}) : Tot (parser32 (coerce_parser t2 p)) =
p32
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.validator_correct
val validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0
val validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0
let validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (consumed) -> Some? gp /\ ( let (Some (_ , consumed')) = gp in U32.v consumed == (consumed' <: nat) )
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 91, "start_col": 0, "start_line": 77 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = () inline_for_extraction let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } ))) inline_for_extraction let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit { t2 == t1 } ) : Tot (parser32 (coerce_parser t2 p)) = p32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> input: LowParse.SLow.Base.bytes32 -> res: FStar.Pervasives.Native.option FStar.UInt32.t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.bytes32", "FStar.Pervasives.Native.option", "FStar.UInt32.t", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "FStar.Bytes.reveal", "FStar.Pervasives.Native.None", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt32.v", "Prims.nat", "Prims.logical", "LowParse.Spec.Base.parse" ]
[]
false
false
false
false
true
let validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0 =
let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some consumed -> Some? gp /\ (let Some (_, consumed') = gp in U32.v consumed == (consumed' <: nat))
false
LowParse.SLow.Base.fst
LowParse.SLow.Base.serialize32_ext
val serialize32_ext (#k1: parser_kind) (#t1: Type) (p1: parser k1 t1) (s1: serializer p1) (s1': serializer32 s1) (#k2: parser_kind) (#t2: Type) (p2: parser k2 t2) (u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input))) : Tot (serializer32 (serialize_ext p1 s1 p2))
val serialize32_ext (#k1: parser_kind) (#t1: Type) (p1: parser k1 t1) (s1: serializer p1) (s1': serializer32 s1) (#k2: parser_kind) (#t2: Type) (p2: parser k2 t2) (u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input))) : Tot (serializer32 (serialize_ext p1 s1 p2))
let serialize32_ext (#k1: parser_kind) (#t1: Type) (p1: parser k1 t1) (s1: serializer p1) (s1': serializer32 s1) (#k2: parser_kind) (#t2: Type) (p2: parser k2 t2) (u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input))) : Tot (serializer32 (serialize_ext p1 s1 p2)) = fun input -> s1' input
{ "file_name": "src/lowparse/LowParse.SLow.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 24, "end_line": 161, "start_col": 0, "start_line": 150 }
module LowParse.SLow.Base include LowParse.Spec.Base module B32 = LowParse.Bytes32 module U32 = FStar.UInt32 let bytes32 = B32.bytes let parser32_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option (t * U32.t)) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (hres, consumed) -> Some? gp /\ ( let (Some (hres' , consumed')) = gp in hres == hres' /\ U32.v consumed == (consumed' <: nat) ) [@unifier_hint_injective] inline_for_extraction let parser32 (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option (t * U32.t) { parser32_correct p input res } ) let parser32_consumes (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (Some? (p32 input) ==> (let (Some (_, consumed)) = p32 input in U32.v consumed <= B32.length input)) = () let parser32_consumes' (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (input: bytes32) : Lemma (match p32 input with | Some (_, consumed) -> U32.v consumed <= B32.length input | _ -> True) = () inline_for_extraction let make_parser32 (#k: parser_kind) (#t: Type) (p: parser k t) (p32: (input: bytes32) -> Pure (option (t * U32.t)) (requires True) (ensures (fun res -> parser32_correct p input res))) : Tot (parser32 p) = (fun (input: bytes32) -> (p32 input <: (res: option (t * U32.t) { parser32_correct p input res } ))) inline_for_extraction let coerce_parser32 (t2: Type) (#k: parser_kind) (#t1: Type) (#p: parser k t1) (p32: parser32 p) (u: unit { t2 == t1 } ) : Tot (parser32 (coerce_parser t2 p)) = p32 let validator_correct (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes32) (res: option U32.t) : GTot Type0 = let gp = parse p (B32.reveal input) in match res with | None -> gp == None | Some (consumed) -> Some? gp /\ ( let (Some (_ , consumed')) = gp in U32.v consumed == (consumed' <: nat) ) let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (input: bytes32) -> Tot (res: option U32.t { validator_correct p input res } ) let serializer32_correct (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 = B32.reveal res == s input let serializer32_correct' (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : GTot Type0 = B32.reveal res `bytes_equal` s input [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (input: t) -> Tot (res: bytes32 { serializer32_correct s input res } ) let serializer32_correct_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (input: t) (res: bytes32) : Lemma (requires (serializer32_correct s input res)) (ensures ( let len = FStar.Bytes.length res in k.parser_kind_low <= len /\ ( match k.parser_kind_high with | Some max -> len <= max | _ -> True ))) [SMTPat (serializer32_correct s input res); SMTPat (FStar.Bytes.length res)] = serialize_length s input
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p1: LowParse.Spec.Base.parser k1 t1 -> s1: LowParse.Spec.Base.serializer p1 -> s1': LowParse.SLow.Base.serializer32 s1 -> p2: LowParse.Spec.Base.parser k2 t2 -> u158: Prims.squash (t1 == t2 /\ (forall (input: LowParse.Bytes.bytes). LowParse.Spec.Base.parse p1 input == LowParse.Spec.Base.parse p2 input)) -> LowParse.SLow.Base.serializer32 (LowParse.Spec.Base.serialize_ext p1 s1 p2)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.l_Forall", "LowParse.Bytes.bytes", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.Base.serialize_ext" ]
[]
false
false
false
false
false
let serialize32_ext (#k1: parser_kind) (#t1: Type) (p1: parser k1 t1) (s1: serializer p1) (s1': serializer32 s1) (#k2: parser_kind) (#t2: Type) (p2: parser k2 t2) (u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input))) : Tot (serializer32 (serialize_ext p1 s1 p2)) =
fun input -> s1' input
false