effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12': accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23': accessor a23) (sq: unit) : Tot (accessor (gaccessor_compose a12 a23))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3
val accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12': accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23': accessor a23) (sq: unit) : Tot (accessor (gaccessor_compose a12 a23)) let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12': accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23': accessor a23) (sq: unit) : Tot (accessor (gaccessor_compose a12 a23)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.Spec.clens", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Low.Base.accessor", "Prims.unit", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.gaccessor_compose_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Low.Base.Spec.clens_compose", "LowParse.Low.Base.Spec.gaccessor_compose", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12': accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23': accessor a23) (sq: unit) : Tot (accessor (gaccessor_compose a12 a23))
[]
LowParse.Low.Base.accessor_compose
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
a12': LowParse.Low.Base.accessor a12 -> a23': LowParse.Low.Base.accessor a23 -> sq: Prims.unit -> LowParse.Low.Base.accessor (LowParse.Low.Base.Spec.gaccessor_compose a12 a23)
{ "end_col": 6, "end_line": 135, "start_col": 2, "start_line": 127 }
FStar.HyperStack.ST.Stack
val jump_serializer (#k #t: _) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ (bytes_of_slice_from h sl pos) `seq_starts_with` sq)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos
val jump_serializer (#k #t: _) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ (bytes_of_slice_from h sl pos) `seq_starts_with` sq)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res)) let jump_serializer (#k #t: _) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ (bytes_of_slice_from h sl pos) `seq_starts_with` sq)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res)) =
true
null
false
let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` (U32.uint_to_t (Ghost.reveal glen))) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Low.Base.jumper", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Ghost.erased", "Prims.unit", "LowParse.Low.Base.Spec.valid_exact_valid", "FStar.Ghost.reveal", "LowParse.Low.Base.Spec.serialize_valid_exact", "Prims._assert", "FStar.Seq.Base.seq", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.Seq.Base.slice", "LowParse.Slice.bytes_of_slice_from", "FStar.Seq.Base.length", "LowParse.Spec.Base.serialize", "FStar.Ghost.hide", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.UInt.uint_t", "FStar.UInt32.n", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.l_and", "LowParse.Slice.live_slice", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.seq_starts_with", "LowParse.Bytes.bytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.int", "Prims.op_Addition" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_serializer (#k #t: _) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ (bytes_of_slice_from h sl pos) `seq_starts_with` sq)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res))
[]
LowParse.Low.Base.jump_serializer
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> j: LowParse.Low.Base.jumper p -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> x: FStar.Ghost.erased t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 10, "end_line": 489, "start_col": 1, "start_line": 482 }
FStar.HyperStack.ST.Stack
val list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ (let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x))))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ ( let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x ) ))) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bres = BF.alloca 0ul 1ul in let h2 = HST.get () in let not_found = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\ L.find f (contents_list p h0 sl pos pos') == L.find f l2 ) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ ( let res = Seq.index (B.as_seq h bres) 0 in U32.v pos <= U32.v res /\ valid p h0 sl res /\ ( let x = contents p h0 sl res in U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\ L.find f (contents_list p h0 sl pos pos') == Some x ))) (fun h h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun pos1 pos2 -> if f' sl pos1 then begin B.upd bres 0ul pos1; false end else true ) in let res = if not_found then pos' else B.index bres 0ul in HST.pop_frame (); res
val list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ (let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x)))) let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ (let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x)))) =
true
null
false
let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bres = BF.alloca 0ul 1ul in let h2 = HST.get () in let not_found = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\ L.find f (contents_list p h0 sl pos pos') == L.find f l2) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h') (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ (let res = Seq.index (B.as_seq h bres) 0 in U32.v pos <= U32.v res /\ valid p h0 sl res /\ (let x = contents p h0 sl res in U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\ L.find f (contents_list p h0 sl pos pos') == Some x))) (fun h h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h') (fun pos1 pos2 -> if f' sl pos1 then (B.upd bres 0ul pos1; false) else true) in let res = if not_found then pos' else B.index bres 0ul in HST.pop_frame (); res
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "Prims.bool", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "LowParse.Low.Base.Spec.contents", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.list_fold_left_gen", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "Prims.list", "LowStar.Monotonic.Buffer.live", "LowParse.Low.Base.Spec.valid_list", "LowParse.Low.Base.Spec.contents_list", "FStar.Pervasives.Native.option", "Prims.b2t", "FStar.List.Tot.Base.find", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "FStar.Pervasives.Native.Some", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Monotonic.Buffer.upd", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.HyperStack.ST.push_frame", "Prims.op_Equality", "FStar.Pervasives.Native.None", "Prims.logical" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out' #pop-options #push-options "--z3rlimit 64 --fuel 2 --ifuel 1" inline_for_extraction let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _ : bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i ) (fun h _ _ _ h' -> // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1); // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk); B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i) ) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then begin B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos' ; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false end else begin B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true end ) in let res = B.index bpos1 0ul in HST.pop_frame (); res inline_for_extraction let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ ( let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x )
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ (let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x))))
[]
LowParse.Low.Base.list_find
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
j: LowParse.Low.Base.jumper p -> f: (_: t -> Prims.bool) -> f': (sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool) -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 5, "end_line": 1692, "start_col": 1, "start_line": 1639 }
Prims.Tot
val leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: (x: bytes -> Lemma (parse p2 x == parse p1 x))) : Tot (leaf_reader p2)
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos
val leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: (x: bytes -> Lemma (parse p2 x == parse p1 x))) : Tot (leaf_reader p2) let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: (x: bytes -> Lemma (parse p2 x == parse p1 x))) : Tot (leaf_reader p2) =
false
null
false
fun #rrel #rel sl pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.leaf_reader", "LowParse.Bytes.bytes", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Base.Spec.valid_facts", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) ))
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: (x: bytes -> Lemma (parse p2 x == parse p1 x))) : Tot (leaf_reader p2)
[]
LowParse.Low.Base.leaf_reader_ext
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p32: LowParse.Low.Base.leaf_reader p1 -> p2: LowParse.Spec.Base.parser k2 t -> lem: (x: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse p2 x == LowParse.Spec.Base.parse p1 x)) -> LowParse.Low.Base.leaf_reader p2
{ "end_col": 12, "end_line": 543, "start_col": 2, "start_line": 536 }
FStar.Pervasives.Lemma
val writable_intro: #t: Type -> #rrel: _ -> #rel: _ -> b: B.mbuffer t rrel rel -> pos: nat -> pos': nat -> h: HS.mem -> squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b) -> f: (s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos) -> Lemma (let s = B.as_seq h b in (Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2))) -> Lemma (writable b pos pos' h)
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f
val writable_intro: #t: Type -> #rrel: _ -> #rel: _ -> b: B.mbuffer t rrel rel -> pos: nat -> pos': nat -> h: HS.mem -> squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b) -> f: (s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos) -> Lemma (let s = B.as_seq h b in (Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2))) -> Lemma (writable b pos pos' h) let writable_intro (#t: Type) (#rrel: _) (#rel: _) (b: B.mbuffer t rrel rel) (pos: nat) (pos': nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: (s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos) -> Lemma (let s = B.as_seq h b in (Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2)))) : Lemma (writable b pos pos' h) =
false
null
true
Classical.forall_intro_2 f
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "lemma" ]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "FStar.Monotonic.HyperStack.mem", "Prims.squash", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowStar.Monotonic.Buffer.length", "FStar.Seq.Properties.lseq", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "FStar.Seq.Properties.replace_subseq", "FStar.Seq.Base.seq", "LowStar.Monotonic.Buffer.as_seq", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.forall_intro_2", "LowParse.Low.Base.writable" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writable_intro: #t: Type -> #rrel: _ -> #rel: _ -> b: B.mbuffer t rrel rel -> pos: nat -> pos': nat -> h: HS.mem -> squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b) -> f: (s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos) -> Lemma (let s = B.as_seq h b in (Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2))) -> Lemma (writable b pos pos' h)
[]
LowParse.Low.Base.writable_intro
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel -> pos: Prims.nat -> pos': Prims.nat -> h: FStar.Monotonic.HyperStack.mem -> _: Prims.squash (LowStar.Monotonic.Buffer.live h b /\ pos <= pos' /\ pos' <= LowStar.Monotonic.Buffer.length b) -> f: (s1: FStar.Seq.Properties.lseq t (pos' - pos) -> s2: FStar.Seq.Properties.lseq t (pos' - pos) -> FStar.Pervasives.Lemma (ensures (let s = LowStar.Monotonic.Buffer.as_seq h b in rel (FStar.Seq.Properties.replace_subseq s pos pos' s1) (FStar.Seq.Properties.replace_subseq s pos pos' s2)))) -> FStar.Pervasives.Lemma (ensures LowParse.Low.Base.writable b pos pos' h)
{ "end_col": 28, "end_line": 576, "start_col": 2, "start_line": 576 }
FStar.Pervasives.Lemma
val writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (sl': Seq.seq t) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos) ) (ensures (let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s'))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
val writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (sl': Seq.seq t) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos) ) (ensures (let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s')) let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (sl': Seq.seq t) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos) ) (ensures (let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s')) =
false
null
true
let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` (Seq.replace_subseq s pos pos' sl))
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "lemma" ]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "FStar.Monotonic.HyperStack.mem", "FStar.Seq.Base.seq", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Properties.replace_subseq", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "Prims.unit", "Prims.l_and", "LowParse.Low.Base.writable", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowStar.Monotonic.Buffer.length", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "Prims.op_Subtraction", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s'
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (sl': Seq.seq t) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos) ) (ensures (let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s'))
[]
LowParse.Low.Base.writable_replace_subseq_elim
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel -> pos: Prims.nat -> pos': Prims.nat -> h: FStar.Monotonic.HyperStack.mem -> sl': FStar.Seq.Base.seq t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\ pos' <= LowStar.Monotonic.Buffer.length b /\ FStar.Seq.Base.length sl' == pos' - pos) (ensures (let s = LowStar.Monotonic.Buffer.as_seq h b in let s' = FStar.Seq.Properties.replace_subseq s pos pos' sl' in rel s s'))
{ "end_col": 57, "end_line": 623, "start_col": 1, "start_line": 621 }
Prims.Tot
val serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash (k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz)) : Tot (serializer32 s)
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len
val serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash (k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz)) : Tot (serializer32 s) let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash (k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz)) : Tot (serializer32 s) =
false
null
false
fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@@ inline_let ]let len = pos' `U32.sub` pos in let h = HST.get () in [@@ inline_let ]let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.Low.Base.leaf_writer_strong", "FStar.UInt32.t", "Prims.squash", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "Prims.unit", "LowParse.Low.Base.Spec.valid_exact_serialize", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Slice.make_slice", "FStar.UInt32.add", "LowParse.Low.Base.Spec.valid_valid_exact", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.UInt32.sub", "LowParse.Low.Base.Spec.serialized_length_eq", "LowParse.Low.Base.serializer32" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz ))
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash (k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz)) : Tot (serializer32 s)
[]
LowParse.Low.Base.serializer32_of_leaf_writer_strong_constant_size
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s32: LowParse.Low.Base.leaf_writer_strong s -> sz: FStar.UInt32.t -> u314: Prims.squash (Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\ Mkparser_kind'?.parser_kind_high k == FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\ Mkparser_kind'?.parser_kind_low k == FStar.UInt32.v sz) -> LowParse.Low.Base.serializer32 s
{ "end_col": 5, "end_line": 981, "start_col": 2, "start_line": 970 }
FStar.Pervasives.Lemma
val wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos': Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base)) (ensures (valid_content_pos p h s pos gv gpos'))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos' : Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires ( wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base )) (ensures ( valid_content_pos p h s pos gv gpos' )) = valid_facts p h s pos
val wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos': Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base)) (ensures (valid_content_pos p h s pos gv gpos')) let wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos': Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base)) (ensures (valid_content_pos p h s pos gv gpos')) =
false
null
true
valid_facts p h s pos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "lemma" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "LowParse.Low.Base.compl_t", "FStar.UInt32.t", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid_facts", "Prims.unit", "Prims.l_and", "LowParse.Low.Base.wvalid", "LowParse.Slice.live_slice", "Prims.eq2", "LowStar.Monotonic.Buffer.as_seq", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "FStar.Ghost.reveal", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out' #pop-options #push-options "--z3rlimit 64 --fuel 2 --ifuel 1" inline_for_extraction let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _ : bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i ) (fun h _ _ _ h' -> // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1); // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk); B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i) ) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then begin B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos' ; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false end else begin B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true end ) in let res = B.index bpos1 0ul in HST.pop_frame (); res inline_for_extraction let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ ( let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x ) ))) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bres = BF.alloca 0ul 1ul in let h2 = HST.get () in let not_found = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\ L.find f (contents_list p h0 sl pos pos') == L.find f l2 ) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ ( let res = Seq.index (B.as_seq h bres) 0 in U32.v pos <= U32.v res /\ valid p h0 sl res /\ ( let x = contents p h0 sl res in U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\ L.find f (contents_list p h0 sl pos pos') == Some x ))) (fun h h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun pos1 pos2 -> if f' sl pos1 then begin B.upd bres 0ul pos1; false end else true ) in let res = if not_found then pos' else B.index bres 0ul in HST.pop_frame (); res #pop-options let rec list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a) : Lemma (L.existsb f l == Some? (L.find f l)) = match l with | [] -> () | x :: q -> if f x then () else list_existsb_find f q inline_for_extraction noextract let list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos') )) = let h = HST.get () in list_existsb_find f (contents_list p h sl pos pos'); let posn = list_find j f f' sl pos pos' in posn <> pos' #push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats" inline_for_extraction noextract let list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } ) (f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1' : U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f' : ( (pos1_: U32.t) -> (pos2_: U32.t) -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ ( let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))) )) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ ( let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y ))) = let hz = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos2_ = BF.alloca pos2 1ul in let h2 = HST.get () in valid_list_nil p2 hz sl2 pos2; let fits = list_fold_left_gen p1 j1 sl1 pos1 pos1' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2)) (fun h ll lr _ -> B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\ B.live h bpos2_ /\ ( let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\ valid_list p2 h sl2 pos2 pos2_ /\ contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (fun h _ _ _ h' -> B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\ U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len ) (fun h h' -> B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1l pos1r -> let pos2_ = B.index bpos2_ 0ul in let h = HST.get () in writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len); valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz; let res = f' pos1l pos2_ in let fits = not (res = max_uint32) in if fits then begin B.upd bpos2_ 0ul res; let h' = HST.get () in writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ; List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1'); list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l]; valid_list_snoc p1 h0 sl1 pos1 pos1l; valid_list_append p2 h' sl2 pos2 pos2_ res; valid_list_nil p2 h' sl2 res; valid_list_append p2 h' sl2 pos2_ res res end else begin let h' = HST.get () in valid_list_cons p1 h0 sl1 pos1l pos1' ; valid_list_append p1 h0 sl1 pos1 pos1l pos1' ; list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1'); serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1'))); serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1'))); valid_list_serialized_list_length s2 h' sl2 pos2 pos2_ end; fits ) in let res = if fits then B.index bpos2_ 0ul else max_uint32 in HST.pop_frame (); res #pop-options #push-options "--z3rlimit 16 --query_stats" inline_for_extraction noextract let list_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } ) (f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1' : U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f' : ( (pos1_: U32.t) -> (pos2_: U32.t) -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ ( let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len else valid_content_pos p2 h' sl2 pos2_ y res ))) )) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ ( let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y ))) = list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1'); list_flatten_map j1 s2 (fun x -> [f x]) h0 sl1 pos1 pos1' sl2 pos2 (fun pos1 pos2 -> let res = f' pos1 pos2 in let h = HST.get () in if res = max_uint32 then begin serialized_list_length_nil s2; serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) [] end else begin valid_list_nil p2 h sl2 res; valid_list_cons p2 h sl2 pos2 res end; res ) (* Example: trivial printers *) inline_for_extraction let print_list (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h')))) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack unit (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h _ h' -> B.modifies B.loc_none h h' )) = let h0 = HST.get () in list_fold_left p j sl pos pos' h0 (Ghost.hide B.loc_none) (fun _ _ _ _ -> True) (fun _ _ _ _ _ -> ()) (fun pos1 _ _ _ _ -> print sl pos1 ) (* Monotonicity *) inline_for_extraction let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte) let wvalid (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos' : Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) : GTot prop = U32.v pos <= U32.v (Ghost.reveal gpos') /\ U32.v (Ghost.reveal gpos') <= U32.v s.len /\ U32.v s.len <= Seq.length x /\ parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\ compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x let wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos' : Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires ( wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base )) (ensures ( valid_content_pos p h s pos gv gpos' ))
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wvalid_valid_content_pos (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) (pos: U32.t) (gpos': Ghost.erased U32.t) (gv: Ghost.erased t) (x: Seq.seq byte) (h: HS.mem) : Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base)) (ensures (valid_content_pos p h s pos gv gpos'))
[]
LowParse.Low.Base.wvalid_valid_content_pos
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> s: LowParse.Slice.slice rrel rel -> compl: LowParse.Low.Base.compl_t t -> pos: FStar.UInt32.t -> gpos': FStar.Ghost.erased FStar.UInt32.t -> gv: FStar.Ghost.erased t -> x: FStar.Seq.Base.seq LowParse.Bytes.byte -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.wvalid p s compl pos gpos' gv x /\ LowParse.Slice.live_slice h s /\ x == LowStar.Monotonic.Buffer.as_seq h (Mkslice?.base s)) (ensures LowParse.Low.Base.Spec.valid_content_pos p h s pos (FStar.Ghost.reveal gv) (FStar.Ghost.reveal gpos'))
{ "end_col": 23, "end_line": 2043, "start_col": 2, "start_line": 2043 }
FStar.HyperStack.ST.Stack
val list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos')))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos') )) = let h = HST.get () in list_existsb_find f (contents_list p h sl pos pos'); let posn = list_find j f f' sl pos pos' in posn <> pos'
val list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos'))) let list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos'))) =
true
null
false
let h = HST.get () in list_existsb_find f (contents_list p h sl pos pos'); let posn = list_find j f f' sl pos pos' in posn <> pos'
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "Prims.bool", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "LowParse.Low.Base.Spec.contents", "Prims.op_disEquality", "LowParse.Low.Base.list_find", "Prims.unit", "LowParse.Low.Base.list_existsb_find", "LowParse.Low.Base.Spec.contents_list", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid_list", "FStar.List.Tot.Base.existsb" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out' #pop-options #push-options "--z3rlimit 64 --fuel 2 --ifuel 1" inline_for_extraction let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _ : bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i ) (fun h _ _ _ h' -> // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1); // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk); B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i) ) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then begin B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos' ; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false end else begin B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true end ) in let res = B.index bpos1 0ul in HST.pop_frame (); res inline_for_extraction let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ ( let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x ) ))) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bres = BF.alloca 0ul 1ul in let h2 = HST.get () in let not_found = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\ L.find f (contents_list p h0 sl pos pos') == L.find f l2 ) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ ( let res = Seq.index (B.as_seq h bres) 0 in U32.v pos <= U32.v res /\ valid p h0 sl res /\ ( let x = contents p h0 sl res in U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\ L.find f (contents_list p h0 sl pos pos') == Some x ))) (fun h h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun pos1 pos2 -> if f' sl pos1 then begin B.upd bres 0ul pos1; false end else true ) in let res = if not_found then pos' else B.index bres 0ul in HST.pop_frame (); res #pop-options let rec list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a) : Lemma (L.existsb f l == Some? (L.find f l)) = match l with | [] -> () | x :: q -> if f x then () else list_existsb_find f q inline_for_extraction noextract let list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos')
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> HST.Stack bool (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos)))) ) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos')))
[]
LowParse.Low.Base.list_existsb
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
j: LowParse.Low.Base.jumper p -> f: (_: t -> Prims.bool) -> f': (sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool) -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool
{ "end_col": 14, "end_line": 1742, "start_col": 1, "start_line": 1739 }
FStar.Pervasives.Lemma
val writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (l: B.loc) (h': HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h'))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
val writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (l: B.loc) (h': HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h')) let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (l: B.loc) (h': HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h')) =
false
null
true
B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "lemma" ]
[ "LowStar.Monotonic.Buffer.srel", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc", "LowParse.Low.Base.writable_replace_subseq", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_buffer_from_to_elim", "FStar.UInt32.uint_to_t", "LowStar.Monotonic.Buffer.len", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer_from_to", "FStar.UInt32.__uint_to_t", "Prims.l_and", "LowParse.Low.Base.writable", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowStar.Monotonic.Buffer.length", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h'
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem) (l: B.loc) (h': HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos'))) h h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h'))
[]
LowParse.Low.Base.writable_modifies
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel -> pos: Prims.nat -> pos': Prims.nat -> h: FStar.Monotonic.HyperStack.mem -> l: LowStar.Monotonic.Buffer.loc -> h': FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\ pos' <= LowStar.Monotonic.Buffer.length b /\ LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_union l (LowStar.Monotonic.Buffer.loc_buffer_from_to b (FStar.UInt32.uint_to_t pos) (FStar.UInt32.uint_to_t pos'))) h h' /\ LowStar.Monotonic.Buffer.loc_disjoint l (LowStar.Monotonic.Buffer.loc_buffer b)) (ensures LowParse.Low.Base.writable b pos pos' h')
{ "end_col": 78, "end_line": 739, "start_col": 2, "start_line": 737 }
FStar.HyperStack.ST.Stack
val copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ (let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos'))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos
val copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ (let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos')) let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ (let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos')) =
true
null
false
let spos' = j src spos in copy_strong p src spos spos' dst dpos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.copy_strong", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Low.Base.Spec.valid", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Slice.live_slice", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "LowStar.Monotonic.Buffer.loc_disjoint", "LowParse.Slice.loc_slice_from", "LowParse.Slice.loc_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.nat", "LowParse.Low.Base.Spec.content_length", "LowStar.Monotonic.Buffer.modifies", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos'
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ (let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos'))
[]
LowParse.Low.Base.copy_strong'
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
j: LowParse.Low.Base.jumper p -> src: LowParse.Slice.slice rrel1 rel1 -> spos: FStar.UInt32.t -> dst: LowParse.Slice.slice rrel2 rel2 -> dpos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 39, "end_line": 1076, "start_col": 1, "start_line": 1075 }
FStar.HyperStack.ST.Stack
val copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ (if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos')))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos
val copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ (if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ (if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) =
true
null
false
let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.copy_weak_with_length", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Low.Base.Spec.valid", "LowParse.Slice.live_slice", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.op_LessThan", "LowParse.Low.ErrorCode.max_uint32", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "LowStar.Monotonic.Buffer.loc_disjoint", "LowParse.Slice.loc_slice_from_to", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Slice.loc_slice_from", "LowStar.Monotonic.Buffer.modifies", "Prims.op_Equality", "Prims.op_GreaterThan", "Prims.bool", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Low.Base.Spec.contents", "Prims.logical" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos'
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos: U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ (if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos')))
[]
LowParse.Low.Base.copy_weak
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> jmp: LowParse.Low.Base.jumper p -> src: LowParse.Slice.slice rrel1 rel1 -> spos: FStar.UInt32.t -> dst: LowParse.Slice.slice rrel2 rel2 -> dpos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 49, "end_line": 1140, "start_col": 1, "start_line": 1139 }
FStar.HyperStack.ST.Stack
val list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos'))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _ : bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i ) (fun h _ _ _ h' -> // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1); // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk); B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i) ) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then begin B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos' ; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false end else begin B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true end ) in let res = B.index bpos1 0ul in HST.pop_frame (); res
val list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos'))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i))) let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos'))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i))) =
true
null
false
let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _:bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h') (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then (B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos'; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false) else (B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true)) in let res = B.index bpos1 0ul in HST.pop_frame (); res
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "Prims.bool", "LowParse.Low.Base.list_fold_left_gen", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "FStar.Monotonic.HyperStack.mem", "Prims.list", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.live", "LowParse.Low.Base.Spec.valid_list", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.List.Tot.Base.length", "LowParse.Low.Base.Spec.contents_list", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint", "LowParse.Low.Base.Spec.valid", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.Base.Spec.contents", "FStar.List.Tot.Base.index", "Prims.op_Equality", "Prims._assert", "LowParse.Low.Base.Spec.valid_list_append", "LowParse.Low.Base.Spec.list_index_append", "LowParse.Low.Base.Spec.valid_list_cons_recip", "LowStar.Monotonic.Buffer.upd", "LowParse.Low.Base.Spec.list_length_append", "Prims.Cons", "Prims.Nil", "LowParse.Low.Base.Spec.valid_list_snoc", "LowStar.Monotonic.Buffer.loc_none", "FStar.HyperStack.ST.get", "FStar.UInt32.add", "LowParse.Low.Base.Spec.valid_list_nil", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.HyperStack.ST.push_frame", "Prims.op_LessThan" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out' #pop-options #push-options "--z3rlimit 64 --fuel 2 --ifuel 1" inline_for_extraction let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos'))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)))
[]
LowParse.Low.Base.list_nth
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> j: LowParse.Low.Base.jumper p -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> i: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 5, "end_line": 1597, "start_col": 1, "start_line": 1530 }
FStar.HyperStack.ST.Stack
val list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))))) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) (#rrel_out #rel_out: _) (sl_out: slice rrel_out rel_out) (pos_out: U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out)) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') ))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out'
val list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))))) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) (#rrel_out #rel_out: _) (sl_out: slice rrel_out rel_out) (pos_out: U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out)) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))))) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) (#rrel_out #rel_out: _) (sl_out: slice rrel_out rel_out) (pos_out: U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out)) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) =
true
null
false
let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos_out':BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ (let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies ((B.loc_buffer bpos_out') `B.loc_union` (loc_slice_from_to sl_out pos_out pos_out')) h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide ((B.loc_buffer bpos_out') `B.loc_union` (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in ((B.loc_buffer bpos_out') `B.loc_union` (loc_slice_from_to sl_out pos_out pos_out')) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then (assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2) else L.append_l_nil (L.filter f (G.reveal l1))); let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out'
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "Prims.bool", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Ghost.erased", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid_content", "FStar.Ghost.reveal", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.list_fold_left", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "LowParse.Slice.loc_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.sub", "Prims.list", "LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq", "LowParse.Low.Base.Spec.valid_list_append", "LowParse.Low.Base.Spec.valid_list_cons", "LowParse.Low.Base.Spec.valid_list_nil", "LowParse.Low.Base.writable_modifies", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.UInt32.v", "Prims.op_Addition", "Prims.op_Subtraction", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "LowParse.Low.Base.copy_strong", "LowParse.Low.Base.writable_weaken", "Prims._assert", "LowStar.Monotonic.Buffer.loc_includes", "FStar.List.Tot.Properties.append_l_nil", "FStar.List.Tot.Base.filter", "LowParse.Low.Base.Spec.list_filter_append", "Prims.Cons", "Prims.Nil", "LowStar.Monotonic.Buffer.live", "LowParse.Low.Base.writable", "LowParse.Low.Base.Spec.valid_list", "LowParse.Low.Base.Spec.contents_list", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowStar.Buffer.pointer", "LowStar.Buffer.alloca", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "FStar.HyperStack.ST.push_frame", "LowParse.Slice.__proj__Mkslice__item__len", "LowStar.Monotonic.Buffer.loc_disjoint", "LowParse.Slice.live_slice" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f': (#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))))) (#rrel #rel: _) (sl: slice rrel rel) (pos pos': U32.t) (#rrel_out #rel_out: _) (sl_out: slice rrel_out rel_out) (pos_out: U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out)) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') ))
[]
LowParse.Low.Base.list_filter
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> j: LowParse.Low.Base.jumper p -> f: (_: t -> Prims.bool) -> f': (sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> x: FStar.Ghost.erased t -> FStar.HyperStack.ST.Stack Prims.bool) -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> sl_out: LowParse.Slice.slice rrel_out rel_out -> pos_out: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 10, "end_line": 1501, "start_col": 1, "start_line": 1449 }
FStar.HyperStack.ST.Stack
val list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0}) (f: (t1 -> Tot (list t2))) (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1': U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f': (pos1_: U32.t -> pos2_: U32.t -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ (let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))))) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ (let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y)))
[ { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } ) (f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1' : U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f' : ( (pos1_: U32.t) -> (pos2_: U32.t) -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ ( let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))) )) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ ( let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y ))) = let hz = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos2_ = BF.alloca pos2 1ul in let h2 = HST.get () in valid_list_nil p2 hz sl2 pos2; let fits = list_fold_left_gen p1 j1 sl1 pos1 pos1' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2)) (fun h ll lr _ -> B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\ B.live h bpos2_ /\ ( let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\ valid_list p2 h sl2 pos2 pos2_ /\ contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (fun h _ _ _ h' -> B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\ U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len ) (fun h h' -> B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1l pos1r -> let pos2_ = B.index bpos2_ 0ul in let h = HST.get () in writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len); valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz; let res = f' pos1l pos2_ in let fits = not (res = max_uint32) in if fits then begin B.upd bpos2_ 0ul res; let h' = HST.get () in writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ; List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1'); list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l]; valid_list_snoc p1 h0 sl1 pos1 pos1l; valid_list_append p2 h' sl2 pos2 pos2_ res; valid_list_nil p2 h' sl2 res; valid_list_append p2 h' sl2 pos2_ res res end else begin let h' = HST.get () in valid_list_cons p1 h0 sl1 pos1l pos1' ; valid_list_append p1 h0 sl1 pos1 pos1l pos1' ; list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1'); serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1'))); serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1'))); valid_list_serialized_list_length s2 h' sl2 pos2 pos2_ end; fits ) in let res = if fits then B.index bpos2_ 0ul else max_uint32 in HST.pop_frame (); res
val list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0}) (f: (t1 -> Tot (list t2))) (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1': U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f': (pos1_: U32.t -> pos2_: U32.t -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ (let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))))) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ (let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) let list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0}) (f: (t1 -> Tot (list t2))) (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1': U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f': (pos1_: U32.t -> pos2_: U32.t -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ (let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))))) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ (let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) =
true
null
false
let hz = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos2_ = BF.alloca pos2 1ul in let h2 = HST.get () in valid_list_nil p2 hz sl2 pos2; let fits = list_fold_left_gen p1 j1 sl1 pos1 pos1' h2 (Ghost.hide ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2))) (fun h ll lr _ -> B.modifies ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2) ) h2 h /\ B.live h bpos2_ /\ (let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\ valid_list p2 h sl2 pos2 pos2_ /\ contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (fun h _ _ _ h' -> B.modifies_only_not_unused_in ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2)) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2) (fun h -> B.modifies ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2) ) h2 h /\ U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len) (fun h h' -> B.modifies_only_not_unused_in ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2)) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2) (fun pos1l pos1r -> let pos2_ = B.index bpos2_ 0ul in let h = HST.get () in writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len); valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz; let res = f' pos1l pos2_ in let fits = not (res = max_uint32) in if fits then (B.upd bpos2_ 0ul res; let h' = HST.get () in writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h'; List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1'); list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l]; valid_list_snoc p1 h0 sl1 pos1 pos1l; valid_list_append p2 h' sl2 pos2 pos2_ res; valid_list_nil p2 h' sl2 res; valid_list_append p2 h' sl2 pos2_ res res) else (let h' = HST.get () in valid_list_cons p1 h0 sl1 pos1l pos1'; valid_list_append p1 h0 sl1 pos1 pos1l pos1'; list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1'); serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1'))); serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1'))); valid_list_serialized_list_length s2 h' sl2 pos2 pos2_); fits) in let res = if fits then B.index bpos2_ 0ul else max_uint32 in HST.pop_frame (); res
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "LowParse.Spec.Base.serializer", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.b2t", "Prims.op_GreaterThan", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.list", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_list", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "LowStar.Monotonic.Buffer.loc_disjoint", "LowParse.Slice.loc_slice_from_to", "LowParse.Slice.loc_slice_from", "Prims.op_LessThan", "LowParse.Low.ErrorCode.max_uint32", "LowStar.Monotonic.Buffer.modifies", "LowParse.Low.Base.Spec.valid", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "LowParse.Slice.live_slice", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.op_Equality", "LowParse.Low.Base.Spec.serialized_list_length", "Prims.bool", "LowParse.Low.Base.Spec.contents_list", "Prims.logical", "LowParse.Low.Base.Spec.contents", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.list_fold_left_gen", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "LowStar.Monotonic.Buffer.live", "FStar.List.Tot.Base.append", "FStar.List.Tot.Base.flatten", "FStar.List.Tot.Base.map", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowParse.Low.Base.Spec.valid_list_append", "LowParse.Low.Base.Spec.valid_list_nil", "LowParse.Low.Base.Spec.valid_list_snoc", "LowParse.Low.Base.Spec.list_flatten_map_append", "Prims.Cons", "Prims.Nil", "FStar.List.Tot.Properties.append_assoc", "LowParse.Low.Base.writable_modifies", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "LowParse.Low.Base.Spec.valid_list_serialized_list_length", "LowParse.Low.Base.Spec.serialized_list_length_append", "LowParse.Low.Base.Spec.valid_list_cons", "Prims.op_Negation", "LowParse.Low.Base.Spec.valid_pos_frame_strong", "LowParse.Low.Base.writable_weaken", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.HyperStack.ST.push_frame" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res #pop-options //B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l) //B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4 module G = FStar.Ghost inline_for_extraction let list_fold_left (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> (l1: Ghost.erased (list t)) -> (x: Ghost.erased t) -> (l2: Ghost.erased (list t)) -> HST.Stack unit (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\ valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\ B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\ inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\ contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2) )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2 )) )) : HST.Stack unit (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h _ h' -> B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos' )) = let _ = list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ()) (fun pos1 pos2 -> let h = HST.get () in valid_list_cons p h sl pos1 pos'; valid_list_append p h sl pos pos1 pos'; body pos1 pos2 (Ghost.hide (contents_list p h sl pos pos1)) (Ghost.hide (contents p h sl pos1)) (Ghost.hide (contents_list p h sl pos2 pos')) ; true ) in () inline_for_extraction let list_length (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in B.fresh_frame_modifies h0 h1; let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in let h2 = HST.get () in list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen)) (fun h l1 l2 pos1 -> B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\ ( let len = U32.v (Seq.index (B.as_seq h blen) 0) in len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow len == L.length l1 )) (fun h l1 l2 pos1 h' -> B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul); Classical.forall_intro_2 (list_length_append #t) ) ; let len = B.index blen 0ul in HST.pop_frame (); len #push-options "--z3rlimit 32 --fuel 2 --ifuel 1" inline_for_extraction let list_filter (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (f: (t -> Tot bool)) (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> (x: Ghost.erased t) -> HST.Stack bool (requires (fun h -> valid_content p h sl pos (G.reveal x))) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x))) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) (#rrel_out #rel_out: _) (sl_out : slice rrel_out rel_out) (pos_out : U32.t) : HST.Stack U32.t (requires (fun h -> U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\ B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ live_slice h sl_out )) (ensures (fun h pos_out' h' -> B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\ U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\ valid_list p h' sl_out pos_out pos_out' /\ contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos') )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in //B.fresh_frame_modifies h0 h1; let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in let h2 = HST.get () in let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 = B.live h bpos_out' /\ ( let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\ valid_list p h sl_out pos_out pos_out' /\ contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\ U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow ) in valid_list_nil p h2 sl_out pos_out; list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos)))) inv (fun h l1 l2 pos1 h' -> let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h'; B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 l1 x l2 -> let pos_out1 = B.index bpos_out' 0ul in list_filter_append f (G.reveal l1) [G.reveal x]; if f' sl pos1 x then begin assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1)))); let h = HST.get () in writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1)); let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in B.upd bpos_out' 0ul pos_out2; let h' = HST.get () in writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h'; valid_list_nil p h' sl_out pos_out2; valid_list_cons p h' sl_out pos_out1 pos_out2; valid_list_append p h' sl_out pos_out pos_out1 pos_out2 end else L.append_l_nil (L.filter f (G.reveal l1)) ) ; let pos_out' = B.index bpos_out' 0ul in HST.pop_frame (); pos_out' #pop-options #push-options "--z3rlimit 64 --fuel 2 --ifuel 1" inline_for_extraction let list_nth (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (i: U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos') )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\ valid_list p h sl (get_valid_pos p h sl res) pos' /\ L.length (contents_list p h sl pos res) == U32.v i /\ contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bpos1 = BF.alloca pos 1ul in let bk = BF.alloca 0ul 1ul in let h2 = HST.get () in valid_list_nil p h0 sl pos; let _ : bool = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> let k = Seq.index (B.as_seq h bk) 0 in B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i ) (fun h _ _ _ h' -> // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1); // assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk); B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> let pos1 = Seq.index (B.as_seq h bpos1) 0 in B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\ valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\ L.length (contents_list p h0 sl pos pos1) == U32.v i /\ contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i) ) (fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2 ) (fun pos1 pos2 -> let k = B.index bk 0ul in if k = i then begin B.upd bpos1 0ul pos1; valid_list_cons_recip p h0 sl pos1 pos'; list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i); valid_list_append p h0 sl pos pos1 pos' ; assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)); false end else begin B.upd bk 0ul (k `U32.add` 1ul); let h = HST.get () in B.modifies_only_not_unused_in B.loc_none h0 h; valid_list_snoc p h0 sl pos pos1; assert (valid p h0 sl pos1); assert (pos2 == get_valid_pos p h0 sl pos1); assert (valid_list p h0 sl pos pos2); list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1]; true end ) in let res = B.index bpos1 0ul in HST.pop_frame (); res inline_for_extraction let list_find (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack U32.t (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let l = contents_list p h sl pos pos' in if res = pos' then L.find f l == None else U32.v pos <= U32.v res /\ valid p h sl res /\ ( let x = contents p h sl res in U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\ L.find f l == Some x ) ))) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bres = BF.alloca 0ul 1ul in let h2 = HST.get () in let not_found = list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1))) (fun h l1 l2 pos1 -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\ L.find f (contents_list p h0 sl pos pos') == L.find f l2 ) (fun h _ _ _ h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun h -> B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\ ( let res = Seq.index (B.as_seq h bres) 0 in U32.v pos <= U32.v res /\ valid p h0 sl res /\ ( let x = contents p h0 sl res in U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\ L.find f (contents_list p h0 sl pos pos') == Some x ))) (fun h h' -> B.loc_unused_in_not_unused_in_disjoint h2; B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h' ) (fun pos1 pos2 -> if f' sl pos1 then begin B.upd bres 0ul pos1; false end else true ) in let res = if not_found then pos' else B.index bres 0ul in HST.pop_frame (); res #pop-options let rec list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a) : Lemma (L.existsb f l == Some? (L.find f l)) = match l with | [] -> () | x :: q -> if f x then () else list_existsb_find f q inline_for_extraction noextract let list_existsb (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (f: (t -> Tot bool)) // should be GTot, but List.find requires Tot (f' : ( (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack bool (requires (fun h -> valid p h sl pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos) )) )) (#rrel #rel: _) (sl: slice rrel rel) (pos pos' : U32.t) : HST.Stack bool (requires (fun h -> valid_list p h sl pos pos')) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos') )) = let h = HST.get () in list_existsb_find f (contents_list p h sl pos pos'); let posn = list_find j f f' sl pos pos' in posn <> pos' #push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats" inline_for_extraction noextract let list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } ) (f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1' : U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f' : ( (pos1_: U32.t) -> (pos2_: U32.t) -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ ( let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))) )) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h )) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ ( let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 256, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_flatten_map (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (j1: jumper p1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0}) (f: (t1 -> Tot (list t2))) (h0: HS.mem) (#rrel1 #rel1: _) (sl1: slice rrel1 rel1) (pos1 pos1': U32.t) (#rrel2 #rel2: _) (sl2: slice rrel2 rel2) (pos2: U32.t { valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\ U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\ B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\ U32.v sl2.len < U32.v max_uint32 }) (f': (pos1_: U32.t -> pos2_: U32.t -> HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\ U32.v pos1 <= U32.v pos1_ /\ U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\ live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\ U32.v pos2_ <= U32.v sl2.len /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2_) h h' /\ (let y = f (contents p1 h0 sl1 pos1_) in if res = max_uint32 then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y ))))) : HST.Stack U32.t (requires (fun h -> B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\ writable sl2.base (U32.v pos2) (U32.v sl2.len) h)) (ensures (fun h res h' -> B.modifies (loc_slice_from sl2 pos2) h h' /\ (let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in if res = max_uint32 then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y)))
[]
LowParse.Low.Base.list_flatten_map
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
j1: LowParse.Low.Base.jumper p1 -> s2: LowParse.Spec.Base.serializer p2 { Mkparser_kind'?.parser_kind_subkind k2 == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\ Mkparser_kind'?.parser_kind_low k2 > 0 } -> f: (_: t1 -> Prims.list t2) -> h0: FStar.Monotonic.HyperStack.mem -> sl1: LowParse.Slice.slice rrel1 rel1 -> pos1: FStar.UInt32.t -> pos1': FStar.UInt32.t -> sl2: LowParse.Slice.slice rrel2 rel2 -> pos2: FStar.UInt32.t { LowParse.Low.Base.Spec.valid_list p1 h0 sl1 pos1 pos1' /\ FStar.UInt32.v pos1 <= FStar.UInt32.v pos1' /\ FStar.UInt32.v pos1' <= FStar.UInt32.v (Mkslice?.len sl1) /\ FStar.UInt32.v pos2 <= FStar.UInt32.v (Mkslice?.len sl2) /\ LowStar.Monotonic.Buffer.loc_disjoint (LowParse.Slice.loc_slice_from_to sl1 pos1 pos1') (LowParse.Slice.loc_slice_from sl2 pos2) /\ FStar.UInt32.v (Mkslice?.len sl2) < FStar.UInt32.v LowParse.Low.ErrorCode.max_uint32 } -> f': (pos1_: FStar.UInt32.t -> pos2_: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t) -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 5, "end_line": 1879, "start_col": 1, "start_line": 1810 }
FStar.HyperStack.ST.Stack
val list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos': U32.t) (h0: HS.mem) (l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')}) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1)) (ensures (inv h' l1 l2 pos1)))) (post_interrupt: (h: HS.mem -> GTot Type0)) (post_interrupt_frame: (h: HS.mem -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h)) (ensures (post_interrupt h')))) (body: (pos1: U32.t -> pos2: U32.t -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1)) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' ((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h'))))) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos)) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')))
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h') )) = HST.push_frame (); let h1 = HST.get () in // B.fresh_frame_modifies h0 h1; let bpos : BF.pointer U32.t = BF.alloca pos 1ul in let bctinue : BF.pointer bool = BF.alloca true 1ul in let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ ( let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h) ) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@inline_let] let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; //assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos')); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1)); valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2)); //assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos')); B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@inline_let] let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> ( B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body ; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in //B.popped_modifies h3 h4; B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@inline_let] let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res
val list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos': U32.t) (h0: HS.mem) (l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')}) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1)) (ensures (inv h' l1 l2 pos1)))) (post_interrupt: (h: HS.mem -> GTot Type0)) (post_interrupt_frame: (h: HS.mem -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h)) (ensures (post_interrupt h')))) (body: (pos1: U32.t -> pos2: U32.t -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1)) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' ((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h'))))) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos)) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h'))) let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos': U32.t) (h0: HS.mem) (l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')}) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1)) (ensures (inv h' l1 l2 pos1)))) (post_interrupt: (h: HS.mem -> GTot Type0)) (post_interrupt_frame: (h: HS.mem -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h)) (ensures (post_interrupt h')))) (body: (pos1: U32.t -> pos2: U32.t -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1)) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' ((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h'))))) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos)) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h'))) =
true
null
false
HST.push_frame (); let h1 = HST.get () in let bpos:BF.pointer U32.t = BF.alloca pos 1ul in let bctinue:BF.pointer bool = BF.alloca true 1ul in let btest:BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in let h2 = HST.get () in assert (B.modifies B.loc_none h0 h2); let test_pre (h: HS.mem) : GTot Type0 = B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (let pos1 = Seq.index (B.as_seq h bpos) 0 in let ctinue = Seq.index (B.as_seq h bctinue) 0 in valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\ B.modifies ((Ghost.reveal l) `B.loc_union` (B.loc_region_only true (HS.get_tip h1))) h2 h /\ Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\ (if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)) in let test_post (cond: bool) (h: HS.mem) : GTot Type0 = test_pre h /\ cond == Seq.index (B.as_seq h btest) 0 in valid_list_nil p h0 sl pos; inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1; inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2; [@@ inline_let ]let while_body () : HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) = let h51 = HST.get () in let pos1 = B.index bpos 0ul in valid_list_cons_recip p h0 sl pos1 pos'; valid_list_cons_recip p h51 sl pos1 pos'; let pos2 = j sl pos1 in let h52 = HST.get () in inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52; B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52; let ctinue = body pos1 pos2 in let h53 = HST.get () in B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1)); valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53; valid_list_snoc p h0 sl pos pos1; B.upd bpos 0ul pos2; B.upd bctinue 0ul ctinue; B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue); let h54 = HST.get () in [@@ inline_let ]let _ = if ctinue then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54 else post_interrupt_frame h53 h54 in () in C.Loops.while #test_pre #test_post (fun (_: unit) -> (B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1))) while_body; valid_list_nil p h0 sl pos'; let res = B.index bctinue 0ul in let h3 = HST.get () in HST.pop_frame (); let h4 = HST.get () in B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3)); [@@ inline_let ]let _ = if res then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4 else post_interrupt_frame h3 h4 in res
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[]
[ "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Low.Base.jumper", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "FStar.Ghost.erased", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_disjoint", "FStar.Ghost.reveal", "LowParse.Slice.loc_slice_from_to", "Prims.list", "Prims.unit", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_unused_in", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.bool", "LowParse.Low.Base.Spec.valid_list", "LowParse.Low.Base.Spec.valid_pos", "LowParse.Low.Base.Spec.contents_list", "Prims.Cons", "LowParse.Low.Base.Spec.contents", "FStar.List.Tot.Base.append", "Prims.logical", "LowStar.Monotonic.Buffer.loc_regions_unused_in", "FStar.Set.singleton", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.get_tip", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.Spec.valid_list_nil", "C.Loops.while", "LowStar.Monotonic.Buffer.upd", "Prims.op_AmpAmp", "FStar.UInt32.lt", "LowParse.Low.Base.Spec.valid_list_snoc", "LowParse.Low.Base.Spec.valid_pos_frame_strong", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowParse.Low.Base.Spec.valid_list_cons_recip", "Prims.eq2", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_region_only", "Prims.op_LessThan", "FStar.UInt32.v", "Prims._assert", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Buffer.pointer", "LowStar.Buffer.alloca", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "FStar.HyperStack.ST.push_frame" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos #pop-options inline_for_extraction let accessor_ext (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (#g: gaccessor p1 p2 cl) (a: accessor g) (cl': clens t1 t2) (sq: squash (clens_eq cl cl')) : Tot (accessor (gaccessor_ext g cl' sq)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_ext g cl' sq) input pos; slice_access_eq h g input pos; gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos) in a input pos #push-options "--z3rlimit 128" // necessary for the .fst #restart-solver // necessary for the .fst inline_for_extraction let accessor_compose (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23) (sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in let pos2 = a12' input pos in let pos3 = a23' input pos2 in slice_access_eq h a12 input pos; slice_access_eq h a23 input pos2; slice_access_eq h (gaccessor_compose a12 a23) input pos; gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos); pos3 #pop-options (* inline_for_extraction let accessor_compose_strong (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl12: clens t1 t2) (#a12: gaccessor p1 p2 cl12) (a12' : accessor a12) (#k3: parser_kind) (#t3: Type) (#p3: parser k3 t3) (#cl23: clens t2 t3) (#a23: gaccessor p2 p3 cl23) (a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } ) (sq: squash (k2.parser_kind_subkind == Some ParserStrong)) : Tot (accessor (gaccessor_compose_strong a12 a23)) = fun #rrel #rel input pos -> let h = HST.get () in slice_access_eq h (gaccessor_compose_strong a12 a23) input pos; slice_access_eq h (gaccessor_compose a12 a23) input pos; accessor_compose a12' a23' () input pos *) (* Validators *) [@unifier_hint_injective] inline_for_extraction let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) [@unifier_hint_injective] inline_for_extraction let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: Ghost.erased (slice rrel rel)) -> (len: U32.t { len == (Ghost.reveal sl).len }) -> (pos: U64.t) -> HST.Stack U64.t (requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( if is_success res then valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res) else (~ (valid p h sl (uint64_to_uint32 pos))) ))) inline_for_extraction let validate_no_read (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator_no_read p) : Tot (validator p) = fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos noextract inline_for_extraction let comment (s: string) : HST.Stack unit (requires (fun _ -> True)) (ensures (fun h _ h' -> h == h')) = LowStar.Comment.comment s noextract inline_for_extraction let validate_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) : Tot (validator p) = fun #rrel #rel sl pos -> comment s; v sl pos inline_for_extraction let validate_with_error_code (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code) : Tot (validator p) = fun #rrel #rel sl pos -> let res = v sl pos in maybe_set_error_code res pos c inline_for_extraction let validate (#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (len: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v len <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ ( let sl = make_slice b len in (res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul)) ))) = if is_error (Cast.uint32_to_uint64 len) then false else [@inline_let] let sl = make_slice b len in is_success (v sl 0uL) let valid_total_constant_size (h: HS.mem) (#k: parser_kind) (#t: Type) (p: parser k t) (sz: nat) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures ( (valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\ (valid p h input pos ==> content_length p h input pos == k.parser_kind_low) )) = parser_kind_prop_equiv k p; valid_facts p h input pos inline_for_extraction let validate_total_constant_size_no_read (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator_no_read p) = fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz then validator_error_not_enough_data else (pos `U64.add` sz) inline_for_extraction let validate_total_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = validate_no_read (validate_total_constant_size_no_read p sz u) inline_for_extraction let validate_total_constant_size_with_error_code (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U64.t) (c: error_code { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U64.v sz /\ k.parser_kind_metadata == Some ParserKindMetadataTotal }) : Tot (validator p) = fun #rrel #rel (input: slice rrel rel) pos -> let h = HST.get () in [@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz then set_validator_error_pos_and_code validator_error_not_enough_data pos c else (pos `U64.add` sz) let valid_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (p2: parser k2 t) (h: HS.mem) #rrel #rel (sl: slice rrel rel) (pos: U32.t) : Lemma (requires (k1 `is_weaker_than` k2)) (ensures ( (valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> ( valid p2 h sl pos /\ valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos) ))) = valid_facts (weaken k1 p2) h sl pos; valid_facts p2 h sl pos inline_for_extraction let validate_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: validator p2 { k1 `is_weaker_than` k2 } ) : Tot (validator (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl (uint64_to_uint32 pos) in v2 sl pos [@unifier_hint_injective] inline_for_extraction let jumper (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p h sl pos)) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ U32.v pos + content_length p h sl pos == U32.v pos' )) inline_for_extraction let jump_constant_size' (#k: parser_kind) (#t: Type) (p: (unit -> GTot (parser k t))) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper (p ())) = fun #rrel #rel (input: slice rrel rel) (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = valid_facts (p ()) h input pos in pos `U32.add` sz inline_for_extraction let jump_constant_size (#k: parser_kind) (#t: Type) (p: parser k t) (sz: U32.t) (u: unit { k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz }) : Tot (jumper p) = jump_constant_size' (fun _ -> p) sz u inline_for_extraction let jump_weaken (k1: parser_kind) (#k2: parser_kind) (#t: Type) (#p2: parser k2 t) (v2: jumper p2 { k1 `is_weaker_than` k2 } ) : Tot (jumper (weaken k1 p2)) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_weaken k1 p2 h sl pos in v2 sl pos let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 = Seq.length sshort <= Seq.length slong /\ Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma (requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3)) (ensures (s1 `seq_starts_with` s3)) = () let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma ((s1 `Seq.append` s2) `seq_starts_with` s1) = () let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2))) (ensures ( s `seq_starts_with` s1 /\ Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2 )) [SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] = let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) inline_for_extraction noextract let jump_serializer (#k: _) (#t: _) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (j: jumper p) (#rrel #rel: _) (sl: slice rrel rel) (pos: U32.t) (x: Ghost.erased t) : HST.Stack U32.t (requires (fun h -> let sq = serialize s (Ghost.reveal x) in live_slice h sl /\ U32.v pos <= U32.v sl.len /\ bytes_of_slice_from h sl pos `seq_starts_with` sq )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res )) = let h = HST.get () in let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x)))); serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos'); valid_exact_valid p h sl pos (Ghost.reveal gpos'); j sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack t (requires (fun h -> valid p h sl pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == contents p h sl pos )) noextract inline_for_extraction let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p) : Tot (leaf_reader p) = fun #rrel #rel sl pos -> comment s; r sl pos [@unifier_hint_injective] inline_for_extraction let leaf_reader_ext (#k1: parser_kind) (#t: Type) (#p1: parser k1 t) (p32: leaf_reader p1) (#k2: parser_kind) (p2: parser k2 t) (lem: ( (x: bytes) -> Lemma (parse p2 x == parse p1 x) )) : Tot (leaf_reader p2) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = valid_facts p1 h sl pos; valid_facts p2 h sl pos; lem (bytes_of_slice_from h sl pos) in p32 sl pos let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) : GTot Type0 = let s = B.as_seq h b in B.live h b /\ ((pos <= pos' /\ pos' <= B.length b) ==> ( (forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)} forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)} Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2 ))) let writable_intro (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b)) (f: ( (s1: Seq.lseq t (pos' - pos)) -> (s2: Seq.lseq t (pos' - pos)) -> Lemma (let s = B.as_seq h b in Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2) )) : Lemma (writable b pos pos' h) = Classical.forall_intro_2 f #push-options "--z3rlimit 32" let writable_weaken (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (lpos lpos' : nat) : Lemma (requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b)) (ensures (writable b lpos lpos' h)) = writable_intro b lpos lpos' h () (fun s1 s2 -> let s = B.as_seq h b in let sl = Seq.slice s pos pos' in let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1); assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2); assert (j1 `rel` j2) ) #pop-options let writable_replace_subseq_elim (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' )) = let s = B.as_seq h b in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) let writable_replace_subseq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (sl' : Seq.seq t) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\ B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\ B.live h' b )) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' h' )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let sl = Seq.slice s pos pos' in assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl); assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl'); writable_intro b pos pos' h' () (fun s1 s2 -> assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1); assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2) ) let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.as_seq h' b `Seq.equal` B.as_seq h b /\ B.live h' b )) (ensures ( writable b pos pos' h' )) = writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' let writable_upd_seq (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (sl' : Seq.seq t) (h: HS.mem) : Lemma (requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)) (ensures ( let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h) )) = let s = B.as_seq h b in let s' = Seq.replace_subseq s pos pos' sl' in let h' = B.g_upd_seq b s' h in B.g_upd_seq_as_seq b s' h; // for live writable_replace_subseq b pos pos' h sl' h' let writable_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (i: nat) (v: t) : Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b)) (ensures ( let s = B.as_seq h b in s `rel` Seq.upd s i v /\ writable b pos pos' (B.g_upd b i v h) )) = let s = B.as_seq h b in let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in writable_upd_seq b pos pos' sl' h; assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') let writable_modifies (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : nat) (h: HS.mem) (l: B.loc) (h' : HS.mem) : Lemma (requires ( writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\ B.loc_disjoint l (B.loc_buffer b) )) (ensures ( writable b pos pos' h' )) = B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h'; writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' inline_for_extraction noextract let mbuffer_upd (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos' : Ghost.erased nat) (i: U32.t) (v: t) : HST.Stack unit (requires (fun h -> writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\ U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\ writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\ B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v )) = let h = HST.get () in writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v; B.g_upd_modifies_strong b (U32.v i) v h; B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h; B.upd' b i v [@unifier_hint_injective] inline_for_extraction let leaf_writer_weak (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> live_slice h sl /\ U32.v pos <= U32.v sl.len /\ U32.v sl.len < U32.v max_uint32 /\ writable sl.base (U32.v pos) (U32.v sl.len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from sl pos) h h' /\ ( if pos' = max_uint32 then U32.v pos + serialized_length s x > U32.v sl.len else valid_content_pos p h' sl pos x pos' ))) [@unifier_hint_injective] inline_for_extraction let leaf_writer_strong (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let sq = B.as_seq h sl.base in let len = serialized_length s x in live_slice h sl /\ U32.v pos + len <= U32.v sl.len /\ writable sl.base (U32.v pos) (U32.v pos + len) h )) (ensures (fun h pos' h' -> B.modifies (loc_slice_from_to sl pos pos') h h' /\ valid_content_pos p h' sl pos x pos' )) [@unifier_hint_injective] inline_for_extraction let serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Tot Type = (x: t) -> (#rrel: _) -> (#rel: _) -> (b: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v pos + len <= B.length b /\ writable b (U32.v pos) (U32.v pos + len) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x ))) inline_for_extraction 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 x #rrel #rel b pos -> s1' x b pos inline_for_extraction let frame_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (x: t) (#rrel: _) (#rel: _) (b: B.mbuffer byte rrel rel) (posl: Ghost.erased U32.t) (posr: Ghost.erased U32.t) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> let len = Seq.length (serialize s x) in let sq = B.as_seq h b in B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\ U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h )) (ensures (fun h len h' -> Seq.length (serialize s x) == U32.v len /\ ( B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\ B.live h b /\ Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\ writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\ Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\ Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) ))) = let h0 = HST.get () in writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x)); let res = s32 x b pos in let h1 = HST.get () in let pos' = pos `U32.add` res in B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos'; writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos; B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos'; B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1; B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr); B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr); B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1; res inline_for_extraction let leaf_writer_strong_of_serializer32 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: serializer32 s) (u: squash (k.parser_kind_subkind == Some ParserStrong)) : Tot (leaf_writer_strong s) = fun x #rrel #rel input pos -> serialized_length_eq s x; let h0 = HST.get () in let len = s32 x input.base pos in [@inline_let] let pos' = pos `U32.add` len in let h = HST.get () in [@inline_let] let _ = let large = bytes_of_slice_from h input pos in let small = bytes_of_slice_from_to h input pos pos' in parse_strong_prefix p small large; valid_facts p h input pos in pos' inline_for_extraction let leaf_writer_weak_of_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\ k.parser_kind_low < U32.v max_uint32 )) : Tot (leaf_writer_weak s) = fun x #rrel #rel input pos -> if (input.len `U32.sub` pos) `U32.lt` sz then max_uint32 else begin let h = HST.get () in writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz); s32 x input pos end inline_for_extraction let serializer32_of_leaf_writer_strong_constant_size (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: leaf_writer_strong s) (sz: U32.t) (u: squash ( k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz )) : Tot (serializer32 s) = fun x #rrel #rel b pos -> serialized_length_eq s x; let h0 = HST.get () in let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in [@inline_let] let len = pos' `U32.sub` pos in let h = HST.get () in [@inline_let] let _ = valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos; valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos' in len inline_for_extraction let blit_strong (#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _) (src: B.mbuffer a rrel1 rel1) (idx_src:U32.t) (dst: B.mbuffer a rrel2 rel2) (idx_dst:U32.t) (len:U32.t) : HST.Stack unit (requires (fun h -> B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\ U32.v idx_dst + U32.v len <= B.length dst /\ B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\ rel2 (B.as_seq h dst) (Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) (Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\ B.live h' dst /\ Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) == Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len) )) = let h = HST.get () in B.blit src idx_src dst idx_dst len; let h' = HST.get () in B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' #push-options "--z3rlimit 16" inline_for_extraction let copy_strong (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos))) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\ dpos' `U32.sub` dpos == spos' `U32.sub` spos )) = let h0 = HST.get () in let len = spos' `U32.sub` spos in valid_facts p h0 src spos; writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos')); blit_strong src.base spos dst.base dpos len; let h = HST.get () in [@inline_let] let dpos' = dpos `U32.add` len in parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos); valid_facts p h dst dpos; dpos' #pop-options inline_for_extraction let copy_strong' (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (#p: parser k t) (j: jumper p) (src: slice rrel1 rel1) // FIXME: length is useless here (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ ( let clen = content_length p h src spos in U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\ writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\ B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))) ))) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from_to dst dpos dpos') h h' /\ valid_content_pos p h' dst dpos (contents p h src spos) dpos' )) = let spos' = j src spos in copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak_with_length (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (src: slice rrel1 rel1) // FIXME: length is useless here (spos spos' : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos) then max_uint32 else copy_strong p src spos spos' dst dpos inline_for_extraction let copy_weak (#rrel1 #rrel2 #rel1 #rel2: _) (#k: parser_kind) (#t: Type) (p: parser k t) (jmp: jumper p) (src: slice rrel1 rel1) (spos : U32.t) (dst: slice rrel2 rel2) (dpos: U32.t) : HST.Stack U32.t (requires (fun h -> k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\ writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\ B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos) )) (ensures (fun h dpos' h' -> B.modifies (loc_slice_from dst dpos) h h' /\ ( if dpos' = max_uint32 then U32.v dpos + content_length p h src spos > U32.v dst.len else valid_content_pos p h' dst dpos (contents p h src spos) dpos' ))) = let spos' = jmp src spos in copy_weak_with_length p src spos spos' dst dpos (* fold_left on lists *) module BF = LowStar.Buffer #push-options "--z3rlimit 256 --fuel 1 --ifuel 1" #restart-solver inline_for_extraction let list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos' : U32.t) (h0: HS.mem) (l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } ) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1 )) (ensures (inv h' l1 l2 pos1))) (post_interrupt: ((h: HS.mem) -> GTot Type0)) (post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires ( B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h )) (ensures (post_interrupt h'))) (body: ( (pos1: U32.t) -> (pos2: U32.t) -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1 )) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h') )) )) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos )) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": false, "smtencoding_l_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": 256, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val list_fold_left_gen (#rrel #rel: _) (#k: parser_kind) (#t: Type) (p: parser k t) (j: jumper p) (sl: slice rrel rel) (pos pos': U32.t) (h0: HS.mem) (l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')}) (inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0)) (inv_frame: (h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1)) (ensures (inv h' l1 l2 pos1)))) (post_interrupt: (h: HS.mem -> GTot Type0)) (post_interrupt_frame: (h: HS.mem -> h': HS.mem -> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h)) (ensures (post_interrupt h')))) (body: (pos1: U32.t -> pos2: U32.t -> HST.Stack bool (requires (fun h -> B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\ valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\ inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1)) (ensures (fun h ctinue h' -> B.modifies (Ghost.reveal l) h h' /\ (if ctinue then inv h' ((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h'))))) : HST.Stack bool (requires (fun h -> h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos)) (ensures (fun h res h' -> B.modifies (Ghost.reveal l) h h' /\ (if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')))
[]
LowParse.Low.Base.list_fold_left_gen
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> j: LowParse.Low.Base.jumper p -> sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> h0: FStar.Monotonic.HyperStack.mem -> l: FStar.Ghost.erased LowStar.Monotonic.Buffer.loc { LowStar.Monotonic.Buffer.loc_disjoint (FStar.Ghost.reveal l) (LowParse.Slice.loc_slice_from_to sl pos pos') } -> inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.list t -> _: Prims.list t -> _: FStar.UInt32.t -> Prims.GTot Type0) -> inv_frame: ( h: FStar.Monotonic.HyperStack.mem -> l1: Prims.list t -> l2: Prims.list t -> pos1: FStar.UInt32.t -> h': FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_unused_in h0) h h' /\ inv h l1 l2 pos1) (ensures inv h' l1 l2 pos1)) -> post_interrupt: (h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0) -> post_interrupt_frame: (h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_unused_in h0) h h' /\ post_interrupt h) (ensures post_interrupt h')) -> body: (pos1: FStar.UInt32.t -> pos2: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool) -> FStar.HyperStack.ST.Stack Prims.bool
{ "end_col": 5, "end_line": 1277, "start_col": 2, "start_line": 1196 }
Prims.Tot
val accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p))
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Low.ErrorCode", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Base.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in [@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos
val accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_id p) input pos in [@@ inline_let ]let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in pos
{ "checked_file": "LowParse.Low.Base.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Comment.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Math.fst.checked", "LowParse.Low.ErrorCode.fst.checked", "LowParse.Low.Base.Spec.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Set.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_id_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Low.Base.Spec.clens_id", "LowParse.Low.Base.Spec.gaccessor_id", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Base include LowParse.Low.Base.Spec include LowParse.Low.ErrorCode module M = LowParse.Math module B = LowStar.Monotonic.Buffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module Seq = FStar.Seq module Cast = FStar.Int.Cast module L = FStar.List.Tot [@unifier_hint_injective] inline_for_extraction let accessor (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) (g: gaccessor p1 p2 cl) : Tot Type = (#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack U32.t (requires (fun h -> valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos) )) (ensures (fun h pos' h' -> B.modifies B.loc_none h h' /\ pos' == slice_access h g sl pos )) #push-options "--z3rlimit 16" inline_for_extraction let make_accessor_from_pure (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#cl: clens t1 t2) ($g: gaccessor p1 p2 cl) (f: ( (input: Ghost.erased bytes) -> Pure U32.t (requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input))) (ensures (fun y -> U32.v y == (g (Ghost.reveal input)))) )) : Tot (accessor g) = fun #rrel #rel sl (pos: U32.t) -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h g sl pos in pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos)) inline_for_extraction let accessor_id (#k: parser_kind) (#t: Type) (p: parser k t)
false
false
LowParse.Low.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (accessor (gaccessor_id p))
[]
LowParse.Low.Base.accessor_id
{ "file_name": "src/lowparse/LowParse.Low.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> LowParse.Low.Base.accessor (LowParse.Low.Base.Spec.gaccessor_id p)
{ "end_col": 5, "end_line": 77, "start_col": 2, "start_line": 73 }
Prims.Tot
val const (k: eqtype) (#v: Type) (y: v) : t k v
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let const (k:eqtype) (#v:Type) (y:v) : t k v = literal (fun x -> Some y)
val const (k: eqtype) (#v: Type) (y: v) : t k v let const (k: eqtype) (#v: Type) (y: v) : t k v =
false
null
false
literal (fun x -> Some y)
{ "checked_file": "FStar.PartialMap.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.PartialMap.fsti" }
[ "total" ]
[ "Prims.eqtype", "FStar.PartialMap.literal", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.option", "FStar.PartialMap.t" ]
[]
(* Copyright 2008-2021 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. Author: Aseem Rastogi *) /// A partial map, partial in the sense that selecting a key in the map may fail /// (by returning None) module FStar.PartialMap /// The main map type val t (k:eqtype) ([@@@strictly_positive] v:Type u#a) : Type u#a /// An empty map val empty (k:eqtype) (v:Type) : t k v /// A constructor that constructs the map from a function val literal (#k:eqtype) (#v:Type) (f:k -> option v) : t k v /// Select a key from the map, may fail by returning None val sel (#k:eqtype) (#v:Type) (m:t k v) (x:k) : option v /// Updating a key in the map val upd (#k:eqtype) (#v:Type) (m:t k v) (x:k) (y:v) : t k v /// Removing a key from the map val remove (#k:eqtype) (#v:Type) (m:t k v) (x:k) : t k v /// Helper function to check if a key exists in the map let contains (#k:eqtype) (#v:Type) (m:t k v) (x:k) : bool = Some? (sel m x) /// A constant map
false
false
FStar.PartialMap.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val const (k: eqtype) (#v: Type) (y: v) : t k v
[]
FStar.PartialMap.const
{ "file_name": "ulib/FStar.PartialMap.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
k: Prims.eqtype -> y: v -> FStar.PartialMap.t k v
{ "end_col": 27, "end_line": 56, "start_col": 2, "start_line": 56 }
Prims.Tot
val contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let contains (#k:eqtype) (#v:Type) (m:t k v) (x:k) : bool = Some? (sel m x)
val contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool let contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool =
false
null
false
Some? (sel m x)
{ "checked_file": "FStar.PartialMap.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.PartialMap.fsti" }
[ "total" ]
[ "Prims.eqtype", "FStar.PartialMap.t", "FStar.Pervasives.Native.uu___is_Some", "FStar.PartialMap.sel", "Prims.bool" ]
[]
(* Copyright 2008-2021 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. Author: Aseem Rastogi *) /// A partial map, partial in the sense that selecting a key in the map may fail /// (by returning None) module FStar.PartialMap /// The main map type val t (k:eqtype) ([@@@strictly_positive] v:Type u#a) : Type u#a /// An empty map val empty (k:eqtype) (v:Type) : t k v /// A constructor that constructs the map from a function val literal (#k:eqtype) (#v:Type) (f:k -> option v) : t k v /// Select a key from the map, may fail by returning None val sel (#k:eqtype) (#v:Type) (m:t k v) (x:k) : option v /// Updating a key in the map val upd (#k:eqtype) (#v:Type) (m:t k v) (x:k) (y:v) : t k v /// Removing a key from the map val remove (#k:eqtype) (#v:Type) (m:t k v) (x:k) : t k v /// Helper function to check if a key exists in the map
false
false
FStar.PartialMap.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool
[]
FStar.PartialMap.contains
{ "file_name": "ulib/FStar.PartialMap.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
m: FStar.PartialMap.t k v -> x: k -> Prims.bool
{ "end_col": 17, "end_line": 51, "start_col": 2, "start_line": 51 }
FStar.HyperStack.ST.Stack
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let uint32s_to_bytes_le len = uints_to_bytes_le #U32 #SEC len
let uint32s_to_bytes_le len =
true
null
false
uints_to_bytes_le #U32 #SEC len
{ "checked_file": "Lib.ByteBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Lib.ByteBuffer.fsti" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.numbytes", "Lib.IntTypes.max_size_t", "Lib.ByteBuffer.uints_to_bytes_le", "Lib.IntTypes.SEC", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.mul", "Lib.IntTypes.mk_int", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.disjoint", "Lib.Buffer.modifies1", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Prims.op_Multiply", "Lib.Buffer.as_seq", "Lib.ByteSequence.uints_to_bytes_le" ]
[]
module Lib.ByteBuffer open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer module B = LowStar.Buffer module BS = Lib.ByteSequence #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" /// Host to {little,big}-endian conversions /// TODO: missing specifications inline_for_extraction val uint_to_be: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_to_le: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_from_be: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_from_le: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l (** Constructs the equality mask for two buffers of secret integers in constant-time *) inline_for_extraction val buf_eq_mask: #t:inttype{~(S128? t)} -> #len1:size_t -> #len2:size_t -> b1:lbuffer (int_t t SEC) len1 -> b2:lbuffer (int_t t SEC) len2 -> len:size_t{v len <= v len1 /\ v len <= v len2} -> res:lbuffer (int_t t SEC) (size 1) -> Stack (int_t t SEC) (requires fun h -> live h b1 /\ live h b2 /\ live h res /\ disjoint res b1 /\ disjoint res b2 /\ v (bget h res 0) == v (ones t SEC)) (ensures fun h0 z h1 -> modifies1 res h0 h1 /\ v z == v (BS.seq_eq_mask (as_seq h0 b1) (as_seq h0 b2) (v len))) (** Compares two buffers of secret bytes of equal length in constant-time, declassifying the result *) inline_for_extraction val lbytes_eq: #len:size_t -> b1:lbuffer uint8 len -> b2:lbuffer uint8 len -> Stack bool (requires fun h -> live h b1 /\ live h b2) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == BS.lbytes_eq (as_seq h0 b1) (as_seq h0 b2)) inline_for_extraction val buf_mask_select: #t:inttype{~(S128? t)} -> #len:size_t -> b1:lbuffer (int_t t SEC) len -> b2:lbuffer (int_t t SEC) len -> mask:int_t t SEC{v mask = 0 \/ v mask = v (ones t SEC)} -> res:lbuffer (int_t t SEC) len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ live h res /\ eq_or_disjoint res b1 /\ eq_or_disjoint res b2) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_seq h1 res == BS.seq_mask_select (as_seq h0 b1) (as_seq h0 b2) mask) inline_for_extraction val uint_from_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> i:lbuffer (uint_t U8 l) (size (numbytes t)) -> Stack (uint_t t l) (requires fun h0 -> live h0 i) (ensures fun h0 o h1 -> h0 == h1 /\ live h1 i /\ o == BS.uint_from_bytes_le #t #l (as_seq h0 i)) inline_for_extraction val uint_from_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> i:lbuffer (uint_t U8 l) (size (numbytes t)) -> Stack (uint_t t l) (requires fun h0 -> live h0 i) (ensures fun h0 o h1 -> h0 == h1 /\ live h1 i /\ o == BS.uint_from_bytes_be #t (as_seq h0 i)) inline_for_extraction val uint_to_bytes_le: #t:inttype{unsigned t} -> #l:secrecy_level -> o:lbuffer (uint_t U8 l) (size (numbytes t)) -> i:uint_t t l -> Stack unit (requires fun h0 -> live h0 o) (ensures fun h0 _ h1 -> live h1 o /\ modifies (loc o) h0 h1 /\ as_seq h1 o == BS.uint_to_bytes_le #t i) inline_for_extraction val uint_to_bytes_be: #t:inttype{unsigned t} -> #l:secrecy_level -> o:lbuffer (uint_t U8 l) (size (numbytes t)) -> i:uint_t t l -> Stack unit (requires fun h0 -> live h0 o) (ensures fun h0 _ h1 -> live h1 o /\ modifies (loc o) h0 h1 /\ as_seq h1 o == BS.uint_to_bytes_be #t i) inline_for_extraction val uints_from_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t t l) len -> i:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_from_bytes_le #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_from_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t t l) len -> i:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_from_bytes_be #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_to_bytes_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> i:lbuffer (uint_t t l) len -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_to_bytes_le #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_to_bytes_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> i:lbuffer (uint_t t l) len -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_to_bytes_be #t #l #(v len) (as_seq h0 i))
false
false
Lib.ByteBuffer.fsti
{ "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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint32s_to_bytes_le : len: Lib.IntTypes.size_t {Lib.IntTypes.v len * Lib.IntTypes.numbytes Lib.IntTypes.U32 <= Lib.IntTypes.max_size_t} -> o: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (Lib.IntTypes.mul len (Lib.IntTypes.mk_int 4)) -> i: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.SEC) len -> FStar.HyperStack.ST.Stack Prims.unit
[]
Lib.ByteBuffer.uint32s_to_bytes_le
{ "file_name": "lib/Lib.ByteBuffer.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Lib.IntTypes.size_t {Lib.IntTypes.v len * Lib.IntTypes.numbytes Lib.IntTypes.U32 <= Lib.IntTypes.max_size_t} -> o: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (Lib.IntTypes.mul len (Lib.IntTypes.mk_int 4)) -> i: Lib.Buffer.lbuffer_t Lib.Buffer.MUT (Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.SEC) len -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 61, "end_line": 172, "start_col": 30, "start_line": 172 }
FStar.HyperStack.ST.Stack
[ { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let uint32s_from_bytes_le #len = uints_from_bytes_le #U32 #SEC #len
let uint32s_from_bytes_le #len =
true
null
false
uints_from_bytes_le #U32 #SEC #len
{ "checked_file": "Lib.ByteBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Lib.ByteBuffer.fsti" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.numbytes", "Lib.IntTypes.max_size_t", "Lib.ByteBuffer.uints_from_bytes_le", "Lib.IntTypes.SEC", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies1", "Prims.eq2", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Lib.ByteSequence.uints_from_bytes_le" ]
[]
module Lib.ByteBuffer open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer module B = LowStar.Buffer module BS = Lib.ByteSequence #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" /// Host to {little,big}-endian conversions /// TODO: missing specifications inline_for_extraction val uint_to_be: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_to_le: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_from_be: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l inline_for_extraction val uint_from_le: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level -> uint_t t l -> uint_t t l (** Constructs the equality mask for two buffers of secret integers in constant-time *) inline_for_extraction val buf_eq_mask: #t:inttype{~(S128? t)} -> #len1:size_t -> #len2:size_t -> b1:lbuffer (int_t t SEC) len1 -> b2:lbuffer (int_t t SEC) len2 -> len:size_t{v len <= v len1 /\ v len <= v len2} -> res:lbuffer (int_t t SEC) (size 1) -> Stack (int_t t SEC) (requires fun h -> live h b1 /\ live h b2 /\ live h res /\ disjoint res b1 /\ disjoint res b2 /\ v (bget h res 0) == v (ones t SEC)) (ensures fun h0 z h1 -> modifies1 res h0 h1 /\ v z == v (BS.seq_eq_mask (as_seq h0 b1) (as_seq h0 b2) (v len))) (** Compares two buffers of secret bytes of equal length in constant-time, declassifying the result *) inline_for_extraction val lbytes_eq: #len:size_t -> b1:lbuffer uint8 len -> b2:lbuffer uint8 len -> Stack bool (requires fun h -> live h b1 /\ live h b2) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == BS.lbytes_eq (as_seq h0 b1) (as_seq h0 b2)) inline_for_extraction val buf_mask_select: #t:inttype{~(S128? t)} -> #len:size_t -> b1:lbuffer (int_t t SEC) len -> b2:lbuffer (int_t t SEC) len -> mask:int_t t SEC{v mask = 0 \/ v mask = v (ones t SEC)} -> res:lbuffer (int_t t SEC) len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ live h res /\ eq_or_disjoint res b1 /\ eq_or_disjoint res b2) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_seq h1 res == BS.seq_mask_select (as_seq h0 b1) (as_seq h0 b2) mask) inline_for_extraction val uint_from_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> i:lbuffer (uint_t U8 l) (size (numbytes t)) -> Stack (uint_t t l) (requires fun h0 -> live h0 i) (ensures fun h0 o h1 -> h0 == h1 /\ live h1 i /\ o == BS.uint_from_bytes_le #t #l (as_seq h0 i)) inline_for_extraction val uint_from_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> i:lbuffer (uint_t U8 l) (size (numbytes t)) -> Stack (uint_t t l) (requires fun h0 -> live h0 i) (ensures fun h0 o h1 -> h0 == h1 /\ live h1 i /\ o == BS.uint_from_bytes_be #t (as_seq h0 i)) inline_for_extraction val uint_to_bytes_le: #t:inttype{unsigned t} -> #l:secrecy_level -> o:lbuffer (uint_t U8 l) (size (numbytes t)) -> i:uint_t t l -> Stack unit (requires fun h0 -> live h0 o) (ensures fun h0 _ h1 -> live h1 o /\ modifies (loc o) h0 h1 /\ as_seq h1 o == BS.uint_to_bytes_le #t i) inline_for_extraction val uint_to_bytes_be: #t:inttype{unsigned t} -> #l:secrecy_level -> o:lbuffer (uint_t U8 l) (size (numbytes t)) -> i:uint_t t l -> Stack unit (requires fun h0 -> live h0 o) (ensures fun h0 _ h1 -> live h1 o /\ modifies (loc o) h0 h1 /\ as_seq h1 o == BS.uint_to_bytes_be #t i) inline_for_extraction val uints_from_bytes_le: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t t l) len -> i:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_from_bytes_le #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_from_bytes_be: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t t l) len -> i:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_from_bytes_be #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_to_bytes_le: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> i:lbuffer (uint_t t l) len -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_to_bytes_le #t #l #(v len) (as_seq h0 i)) inline_for_extraction val uints_to_bytes_be: #t:inttype{unsigned t} -> #l:secrecy_level -> len:size_t{v len * numbytes t <= max_size_t} -> o:lbuffer (uint_t U8 l) (len *! size (numbytes t)) -> i:lbuffer (uint_t t l) len -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 _ h1 -> modifies1 o h0 h1 /\ as_seq h1 o == BS.uints_to_bytes_be #t #l #(v len) (as_seq h0 i)) inline_for_extraction let uint32s_to_bytes_le len = uints_to_bytes_le #U32 #SEC len
false
false
Lib.ByteBuffer.fsti
{ "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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint32s_from_bytes_le : o: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t Lib.IntTypes.U32 Lib.IntTypes.SEC) len -> i: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (len *! Lib.IntTypes.size (Lib.IntTypes.numbytes Lib.IntTypes.U32)) -> FStar.HyperStack.ST.Stack Prims.unit
[]
Lib.ByteBuffer.uint32s_from_bytes_le
{ "file_name": "lib/Lib.ByteBuffer.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
o: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t Lib.IntTypes.U32 Lib.IntTypes.SEC) len -> i: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t Lib.IntTypes.U8 Lib.IntTypes.SEC) (len *! Lib.IntTypes.size (Lib.IntTypes.numbytes Lib.IntTypes.U32)) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 67, "end_line": 175, "start_col": 33, "start_line": 175 }
Prims.Tot
val va_ens_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_sM: va_state) (va_fM: va_fuel) : prop
[ { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))))))))))))))))))))))
val va_ens_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_sM: va_state) (va_fM: va_fuel) : prop let va_ens_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_sM: va_state) (va_fM: va_fuel) : prop =
false
null
false
(va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM ( va_update_reg64 rR10 va_sM ( va_update_reg64 rR9 va_sM ( va_update_reg64 rR8 va_sM ( va_update_reg64 rRsp va_sM ( va_update_reg64 rRbp va_sM ( va_update_reg64 rRdi va_sM ( va_update_reg64 rRsi va_sM ( va_update_reg64 rRdx va_sM ( va_update_reg64 rRcx va_sM ( va_update_reg64 rRbx va_sM ( va_update_reg64 rRax va_sM ( va_update_ok va_sM ( va_update_mem va_sM va_s0 ) ) ) ) ) ) ) ) ) ) ) ) ) )) )))))))))))) )))))))))))
{ "checked_file": "Vale.Test.X64.Args.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Test.X64.Args.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Prims.bool", "Vale.X64.Memory.buffer64", "Vale.X64.Decls.va_fuel", "Prims.l_and", "Vale.Test.X64.Args.va_req_Test", "Vale.X64.Decls.va_ensure_total", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Prims.eq2", "Vale.Def.Types_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRsp", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRbp", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR13", "Vale.X64.Machine_s.rR14", "Vale.X64.Machine_s.rR15", "Prims.l_imp", "Vale.X64.Machine_s.rRdi", "Vale.X64.Machine_s.rRsi", "Vale.X64.Decls.quad32", "Vale.X64.Decls.va_get_xmm", "Vale.X64.Decls.modifies_mem", "Vale.X64.Memory.loc_none", "Vale.X64.Decls.va_get_mem", "Vale.X64.Decls.va_state_eq", "Vale.X64.Decls.va_update_mem_layout", "Vale.X64.Decls.va_update_mem_heaplet", "Vale.X64.Decls.va_update_flags", "Vale.X64.Decls.va_update_xmm", "Vale.X64.Decls.va_update_reg64", "Vale.X64.Machine_s.rR11", "Vale.X64.Machine_s.rR10", "Vale.X64.Machine_s.rR9", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_update_ok", "Vale.X64.Decls.va_update_mem", "Prims.prop" ]
[]
module Vale.Test.X64.Args open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.QuickCode open Vale.X64.QuickCodes #set-options "--z3rlimit 20" //-- Test val va_code_Test : win:bool -> Tot va_code val va_codegen_success_Test : win:bool -> Tot va_pbool let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : prop = (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret) let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64)
false
true
Vale.Test.X64.Args.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_ens_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_sM: va_state) (va_fM: va_fuel) : prop
[]
Vale.Test.X64.Args.va_ens_Test
{ "file_name": "obj/Vale.Test.X64.Args.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> win: Prims.bool -> arg0: Vale.X64.Memory.buffer64 -> arg1: Vale.X64.Memory.buffer64 -> arg2: Vale.X64.Memory.buffer64 -> arg3: Vale.X64.Memory.buffer64 -> arg4: Vale.X64.Memory.buffer64 -> arg5: Vale.X64.Memory.buffer64 -> arg6: Vale.X64.Memory.buffer64 -> arg7: Vale.X64.Memory.buffer64 -> va_sM: Vale.X64.Decls.va_state -> va_fM: Vale.X64.Decls.va_fuel -> Prims.prop
{ "end_col": 88, "end_line": 78, "start_col": 2, "start_line": 54 }
Prims.Tot
val va_req_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : prop
[ { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : prop = (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)
val va_req_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : prop let va_req_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : prop =
false
null
false
(va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)
{ "checked_file": "Vale.Test.X64.Args.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Test.X64.Args.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Prims.bool", "Vale.X64.Memory.buffer64", "Prims.l_and", "Vale.X64.Decls.va_require_total", "Vale.Test.X64.Args.va_code_Test", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Prims.eq2", "Vale.Def.Words_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRsp", "Vale.X64.Stack_i.init_rsp", "Vale.X64.Decls.va_get_stack", "Vale.X64.Memory.is_initial_heap", "Vale.X64.Decls.va_get_mem_layout", "Vale.X64.Decls.va_get_mem", "Prims.l_imp", "Vale.X64.Stack_i.valid_src_stack64", "Prims.op_Addition", "Prims.l_not", "Vale.X64.Decls.validSrcAddrs64", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdi", "Prims.int", "Vale.Arch.HeapTypes_s.Secret", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rR9", "Vale.X64.Stack_i.load_stack64", "Prims.prop" ]
[]
module Vale.Test.X64.Args open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.QuickCode open Vale.X64.QuickCodes #set-options "--z3rlimit 20" //-- Test val va_code_Test : win:bool -> Tot va_code val va_codegen_success_Test : win:bool -> Tot va_pbool let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) :
false
true
Vale.Test.X64.Args.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_req_Test (va_b0: va_code) (va_s0: va_state) (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : prop
[]
Vale.Test.X64.Args.va_req_Test
{ "file_name": "obj/Vale.Test.X64.Args.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> win: Prims.bool -> arg0: Vale.X64.Memory.buffer64 -> arg1: Vale.X64.Memory.buffer64 -> arg2: Vale.X64.Memory.buffer64 -> arg3: Vale.X64.Memory.buffer64 -> arg4: Vale.X64.Memory.buffer64 -> arg5: Vale.X64.Memory.buffer64 -> arg6: Vale.X64.Memory.buffer64 -> arg7: Vale.X64.Memory.buffer64 -> Prims.prop
{ "end_col": 100, "end_line": 50, "start_col": 2, "start_line": 22 }
Prims.Tot
val va_wp_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
[ { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_wp_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0)) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR8 va_s0)) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR9 va_s0)) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0))) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0))) arg7 0 (va_get_mem_layout va_s0) Secret /\ (forall (va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_rsi:nat64) (va_x_rdi:nat64) (va_x_rbp:nat64) (va_x_rsp:nat64) (va_x_r8:nat64) (va_x_r9:nat64) (va_x_r10:nat64) (va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_r14:nat64) (va_x_r15:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_xmm15:quad32) (va_x_efl:Vale.X64.Flags.t) (va_x_heap0:vale_heap) (va_x_memLayout:vale_heap_layout) . let va_sM = va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 0 va_x_heap0 (va_upd_flags va_x_efl (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRsp va_x_rsp (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRsi va_x_rsi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRbx va_x_rbx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (())))
val va_wp_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 let va_wp_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
false
null
false
(va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0)) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR8 va_s0)) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR9 va_s0)) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0))) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0))) arg7 0 (va_get_mem_layout va_s0) Secret /\ (forall (va_x_mem: vale_heap) (va_x_rax: nat64) (va_x_rbx: nat64) (va_x_rcx: nat64) (va_x_rdx: nat64) (va_x_rsi: nat64) (va_x_rdi: nat64) (va_x_rbp: nat64) (va_x_rsp: nat64) (va_x_r8: nat64) (va_x_r9: nat64) (va_x_r10: nat64) (va_x_r11: nat64) (va_x_r12: nat64) (va_x_r13: nat64) (va_x_r14: nat64) (va_x_r15: nat64) (va_x_xmm0: quad32) (va_x_xmm1: quad32) (va_x_xmm2: quad32) (va_x_xmm3: quad32) (va_x_xmm4: quad32) (va_x_xmm5: quad32) (va_x_xmm6: quad32) (va_x_xmm7: quad32) (va_x_xmm8: quad32) (va_x_xmm9: quad32) (va_x_xmm10: quad32) (va_x_xmm11: quad32) (va_x_xmm12: quad32) (va_x_xmm13: quad32) (va_x_xmm14: quad32) (va_x_xmm15: quad32) (va_x_efl: Vale.X64.Flags.t) (va_x_heap0: vale_heap) (va_x_memLayout: vale_heap_layout). let va_sM = va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 0 va_x_heap0 (va_upd_flags va_x_efl (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11 ( va_upd_reg64 rR10 va_x_r10 ( va_upd_reg64 rR9 va_x_r9 ( va_upd_reg64 rR8 va_x_r8 ( va_upd_reg64 rRsp va_x_rsp ( va_upd_reg64 rRbp va_x_rbp ( va_upd_reg64 rRdi va_x_rdi ( va_upd_reg64 rRsi va_x_rsi ( va_upd_reg64 rRdx va_x_rdx ( va_upd_reg64 rRcx va_x_rcx ( va_upd_reg64 rRbx va_x_rbx ( va_upd_reg64 rRax va_x_rax ( va_upd_mem va_x_mem va_s0 ) ) ) ) ) ) ) ) ) ) ) ) )) )))))))))) ))))))))))) in va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (())))
{ "checked_file": "Vale.Test.X64.Args.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Test.X64.Args.fsti" }
[ "total" ]
[ "Prims.bool", "Vale.X64.Memory.buffer64", "Vale.X64.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Prims.eq2", "Vale.Def.Words_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRsp", "Vale.X64.Stack_i.init_rsp", "Vale.X64.Decls.va_get_stack", "Vale.X64.Memory.is_initial_heap", "Vale.X64.Decls.va_get_mem_layout", "Vale.X64.Decls.va_get_mem", "Prims.l_imp", "Vale.X64.Stack_i.valid_src_stack64", "Prims.op_Addition", "Prims.l_not", "Vale.X64.Decls.validSrcAddrs64", "Vale.X64.Decls.va_if", "Vale.Def.Types_s.nat64", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdi", "Vale.Arch.HeapTypes_s.Secret", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rR9", "Vale.X64.Memory.nat64", "Vale.X64.Stack_i.load_stack64", "Prims.l_Forall", "Vale.X64.InsBasic.vale_heap", "Vale.X64.Decls.quad32", "Vale.X64.Flags.t", "Vale.Arch.HeapImpl.vale_heap_layout", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRbp", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR13", "Vale.X64.Machine_s.rR14", "Vale.X64.Machine_s.rR15", "Vale.X64.Decls.va_get_xmm", "Vale.X64.Decls.modifies_mem", "Vale.X64.Memory.loc_none", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_upd_mem_layout", "Vale.X64.Decls.va_upd_mem_heaplet", "Vale.X64.Decls.va_upd_flags", "Vale.X64.Decls.va_upd_xmm", "Vale.X64.Decls.va_upd_reg64", "Vale.X64.Machine_s.rR11", "Vale.X64.Machine_s.rR10", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_upd_mem" ]
[]
module Vale.Test.X64.Args open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.QuickCode open Vale.X64.QuickCodes #set-options "--z3rlimit 20" //-- Test val va_code_Test : win:bool -> Tot va_code val va_codegen_success_Test : win:bool -> Tot va_pbool let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : prop = (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret) let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))))))))))))))))) val va_lemma_Test : va_b0:va_code -> va_s0:va_state -> win:bool -> arg0:buffer64 -> arg1:buffer64 -> arg2:buffer64 -> arg3:buffer64 -> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 -> arg7:buffer64 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))))))))))))))))))))))) [@ va_qattr] let va_wp_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_s0:va_state) (va_k:(va_state
false
true
Vale.Test.X64.Args.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_wp_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
[]
Vale.Test.X64.Args.va_wp_Test
{ "file_name": "obj/Vale.Test.X64.Args.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
win: Prims.bool -> arg0: Vale.X64.Memory.buffer64 -> arg1: Vale.X64.Memory.buffer64 -> arg2: Vale.X64.Memory.buffer64 -> arg3: Vale.X64.Memory.buffer64 -> arg4: Vale.X64.Memory.buffer64 -> arg5: Vale.X64.Memory.buffer64 -> arg6: Vale.X64.Memory.buffer64 -> arg7: Vale.X64.Memory.buffer64 -> va_s0: Vale.X64.Decls.va_state -> va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
{ "end_col": 72, "end_line": 204, "start_col": 2, "start_line": 143 }
Prims.Tot
val va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : (va_quickCode unit (va_code_Test win))
[ { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Test.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_quick_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : (va_quickCode unit (va_code_Test win)) = (va_QProc (va_code_Test win) ([va_Mod_mem_layout; va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRsp; va_Mod_reg64 rRbp; va_Mod_reg64 rRdi; va_Mod_reg64 rRsi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) (va_wp_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7) (va_wpProof_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7))
val va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : (va_quickCode unit (va_code_Test win)) let va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : (va_quickCode unit (va_code_Test win)) =
false
null
false
(va_QProc (va_code_Test win) ([ va_Mod_mem_layout; va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRsp; va_Mod_reg64 rRbp; va_Mod_reg64 rRdi; va_Mod_reg64 rRsi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem ]) (va_wp_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7) (va_wpProof_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7))
{ "checked_file": "Vale.Test.X64.Args.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Test.X64.Args.fsti" }
[ "total" ]
[ "Prims.bool", "Vale.X64.Memory.buffer64", "Vale.X64.QuickCode.va_QProc", "Prims.unit", "Vale.Test.X64.Args.va_code_Test", "Prims.Cons", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.va_Mod_mem_layout", "Vale.X64.QuickCode.va_Mod_mem_heaplet", "Vale.X64.QuickCode.va_Mod_flags", "Vale.X64.QuickCode.va_Mod_xmm", "Vale.X64.QuickCode.va_Mod_reg64", "Vale.X64.Machine_s.rR15", "Vale.X64.Machine_s.rR14", "Vale.X64.Machine_s.rR13", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR11", "Vale.X64.Machine_s.rR10", "Vale.X64.Machine_s.rR9", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRsp", "Vale.X64.Machine_s.rRbp", "Vale.X64.Machine_s.rRdi", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRax", "Vale.X64.QuickCode.va_Mod_mem", "Prims.Nil", "Vale.Test.X64.Args.va_wp_Test", "Vale.Test.X64.Args.va_wpProof_Test", "Vale.X64.QuickCode.va_quickCode" ]
[]
module Vale.Test.X64.Args open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.QuickCode open Vale.X64.QuickCodes #set-options "--z3rlimit 20" //-- Test val va_code_Test : win:bool -> Tot va_code val va_codegen_success_Test : win:bool -> Tot va_pbool let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : prop = (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret) let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))))))))))))))))) val va_lemma_Test : va_b0:va_code -> va_s0:va_state -> win:bool -> arg0:buffer64 -> arg1:buffer64 -> arg2:buffer64 -> arg3:buffer64 -> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 -> arg7:buffer64 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0) else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))))))))))))))))))))))) [@ va_qattr] let va_wp_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)) arg0 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)) arg1 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)) arg2 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0)) arg3 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR8 va_s0)) arg4 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun _ -> va_get_reg64 rR9 va_s0)) arg5 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0))) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0))) arg7 0 (va_get_mem_layout va_s0) Secret /\ (forall (va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_rsi:nat64) (va_x_rdi:nat64) (va_x_rbp:nat64) (va_x_rsp:nat64) (va_x_r8:nat64) (va_x_r9:nat64) (va_x_r10:nat64) (va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64) (va_x_r14:nat64) (va_x_r15:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32) (va_x_xmm8:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32) (va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_xmm15:quad32) (va_x_efl:Vale.X64.Flags.t) (va_x_heap0:vale_heap) (va_x_memLayout:vale_heap_layout) . let va_sM = va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 0 va_x_heap0 (va_upd_flags va_x_efl (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13 (va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9 va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14 (va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11 (va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRsp va_x_rsp (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRsi va_x_rsi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRbx va_x_rbx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))))))))))))))))))))))) in va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (()))) val va_wpProof_Test : win:bool -> arg0:buffer64 -> arg1:buffer64 -> arg2:buffer64 -> arg3:buffer64 -> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 -> arg7:buffer64 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Test win) ([va_Mod_mem_layout; va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRsp; va_Mod_reg64 rRbp; va_Mod_reg64 rRdi; va_Mod_reg64 rRsi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : (va_quickCode unit
false
false
Vale.Test.X64.Args.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64) : (va_quickCode unit (va_code_Test win))
[]
Vale.Test.X64.Args.va_quick_Test
{ "file_name": "obj/Vale.Test.X64.Args.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
win: Prims.bool -> arg0: Vale.X64.Memory.buffer64 -> arg1: Vale.X64.Memory.buffer64 -> arg2: Vale.X64.Memory.buffer64 -> arg3: Vale.X64.Memory.buffer64 -> arg4: Vale.X64.Memory.buffer64 -> arg5: Vale.X64.Memory.buffer64 -> arg6: Vale.X64.Memory.buffer64 -> arg7: Vale.X64.Memory.buffer64 -> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Test.X64.Args.va_code_Test win)
{ "end_col": 97, "end_line": 231, "start_col": 2, "start_line": 224 }
FStar.Pervasives.Lemma
val no_extra_bytes_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 0 <= num_bytes /\ num_bytes % 16 == 0 /\ length s == bytes_to_quad_size num_bytes) (ensures slice (le_seq_quad32_to_bytes s) 0 num_bytes == le_seq_quad32_to_bytes s /\ slice s 0 (num_bytes / 16) == s)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s)
val no_extra_bytes_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 0 <= num_bytes /\ num_bytes % 16 == 0 /\ length s == bytes_to_quad_size num_bytes) (ensures slice (le_seq_quad32_to_bytes s) 0 num_bytes == le_seq_quad32_to_bytes s /\ slice s 0 (num_bytes / 16) == s) let no_extra_bytes_helper s num_bytes =
false
null
true
slice_length (le_seq_quad32_to_bytes s)
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.int", "FStar.Seq.Properties.slice_length", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Prims.unit" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = ()
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": 25, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val no_extra_bytes_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 0 <= num_bytes /\ num_bytes % 16 == 0 /\ length s == bytes_to_quad_size num_bytes) (ensures slice (le_seq_quad32_to_bytes s) 0 num_bytes == le_seq_quad32_to_bytes s /\ slice s 0 (num_bytes / 16) == s)
[]
Vale.AES.GCM_helpers.no_extra_bytes_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 0 <= num_bytes /\ num_bytes % 16 == 0 /\ FStar.Seq.Base.length s == Vale.AES.GCM_helpers.bytes_to_quad_size num_bytes) (ensures FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) 0 num_bytes == Vale.Def.Types_s.le_seq_quad32_to_bytes s /\ FStar.Seq.Base.slice s 0 (num_bytes / 16) == s)
{ "end_col": 41, "end_line": 29, "start_col": 2, "start_line": 29 }
FStar.Pervasives.Lemma
val le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0)) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra in x == x'))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); ()
val le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0)) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra in x == x')) let le_seq_quad32_to_bytes_tail_prefix (s: seq quad32) (num_bytes: nat) =
false
null
true
let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra ); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "Prims.eq2", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes", "FStar.Seq.Base.create", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.index", "Prims.int", "Prims.op_Division", "Prims.op_Modulus" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s)
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": 25, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0)) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra in x == x'))
[]
Vale.AES.GCM_helpers.le_seq_quad32_to_bytes_tail_prefix
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\ 16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes (FStar.Seq.Base.index s num_blocks)) 0 num_extra in x == x'))
{ "end_col": 4, "end_line": 48, "start_col": 71, "start_line": 31 }
FStar.Pervasives.Lemma
val pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () )
val pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) let pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) =
false
null
true
let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then (assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l (pad_to_128_bits partial_bytes); ()) else (assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then (lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); ()) else (let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); ()); ())
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.op_LessThan", "FStar.Seq.Base.length", "Prims.unit", "FStar.Seq.Base.append_empty_l", "Vale.AES.GCTR_s.pad_to_128_bits", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.empty", "Prims.bool", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.op_At_Bar", "FStar.Seq.Properties.lemma_split", "FStar.Seq.Base.equal", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Prims.op_Subtraction", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": 25, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
[]
Vale.AES.GCM_helpers.pad_to_128_bits_multiples
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (ensures (let full_blocks = (FStar.Seq.Base.length b / 16) * 16 in let _ = FStar.Seq.Properties.split b full_blocks in (let FStar.Pervasives.Native.Mktuple2 #_ #_ full_bytes partial_bytes = _ in Vale.AES.GCTR_s.pad_to_128_bits b == full_bytes @| Vale.AES.GCTR_s.pad_to_128_bits partial_bytes) <: Type0))
{ "end_col": 3, "end_line": 88, "start_col": 3, "start_line": 65 }
FStar.Pervasives.Lemma
val pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in length final_quads == 1 /\ (let final_quad = index final_quads 0 in pad_to_128_bits (slice (le_seq_quad32_to_bytes s) 0 num_bytes) == le_seq_quad32_to_bytes full_quads @| pad_to_128_bits (slice (le_quad32_to_bytes final_quad) 0 (num_bytes % 16)))))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; ()
val pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in length final_quads == 1 /\ (let final_quad = index final_quads 0 in pad_to_128_bits (slice (le_seq_quad32_to_bytes s) 0 num_bytes) == le_seq_quad32_to_bytes full_quads @| pad_to_128_bits (slice (le_quad32_to_bytes final_quad) 0 (num_bytes % 16))))) let pad_to_128_bits_le_quad32_to_bytes (s: seq quad32) (num_bytes: int) =
false
null
true
let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads, final_quads = split s num_blocks in assert (length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.int", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCM_helpers.le_seq_quad32_to_bytes_tail_prefix", "FStar.Seq.Properties.slice_slice", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Prims._assert", "Prims.eq2", "Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes0", "FStar.Pervasives.Native.tuple2", "Vale.Def.Words_s.nat8", "FStar.Seq.Properties.split", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Seq.Base.length", "Vale.AES.GCM_helpers.pad_to_128_bits_multiples", "FStar.Seq.Base.slice", "FStar.Seq.Base.index", "Prims.op_Modulus" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () )
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "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": 25, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in length final_quads == 1 /\ (let final_quad = index final_quads 0 in pad_to_128_bits (slice (le_seq_quad32_to_bytes s) 0 num_bytes) == le_seq_quad32_to_bytes full_quads @| pad_to_128_bits (slice (le_quad32_to_bytes final_quad) 0 (num_bytes % 16)))))
[]
Vale.AES.GCM_helpers.pad_to_128_bits_le_quad32_to_bytes
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\ 16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ FStar.Seq.Base.length s == Vale.AES.GCM_helpers.bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let _ = FStar.Seq.Properties.split s num_blocks in (let FStar.Pervasives.Native.Mktuple2 #_ #_ full_quads final_quads = _ in FStar.Seq.Base.length final_quads == 1 /\ (let final_quad = FStar.Seq.Base.index final_quads 0 in Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) 0 num_bytes) == Vale.Def.Types_s.le_seq_quad32_to_bytes full_quads @| Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes final_quad) 0 (num_bytes % 16)))) <: Type0))
{ "end_col": 4, "end_line": 132, "start_col": 71, "start_line": 90 }
FStar.Pervasives.Lemma
val lemma_mod_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
val lemma_mod_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) let lemma_mod_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) =
false
null
true
hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Vale.AES.GCM_helpers.lemma_mod_n_8_lower2", "Vale.Def.Words_s.Mkfour", "Prims.unit", "Vale.Arch.Types.lo64_reveal", "Vale.Arch.Types.hi64_reveal", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Arch.Types.hi64", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
[]
Vale.AES.GCM_helpers.lemma_mod_n_8_upper2
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures Vale.Arch.Types.hi64 q % Prims.pow2 (8 * (4 + n)) == Mkfour?.hi2 q + 0x100000000 * (Mkfour?.hi3 q % Prims.pow2 (8 * n)))
{ "end_col": 43, "end_line": 335, "start_col": 2, "start_line": 332 }
FStar.Pervasives.Lemma
val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); ()
val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) let lemma_four_zero (_: unit) : Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) =
false
null
true
let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_LE", "Vale.Def.Words.Four_s.four_to_nat_unfold", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Prims.l_True", "Prims.squash", "Prims.int", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); le_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0)
[]
Vale.AES.GCM_helpers.lemma_four_zero
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.create 4 0)) == 0)
{ "end_col": 4, "end_line": 421, "start_col": 3, "start_line": 418 }
FStar.Pervasives.Lemma
val lemma_mod_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
val lemma_mod_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) let lemma_mod_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) =
false
null
true
hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Vale.AES.GCM_helpers.lemma_mod_n_8_lower1", "Vale.Def.Words_s.Mkfour", "Prims.unit", "Vale.Arch.Types.lo64_reveal", "Vale.Arch.Types.hi64_reveal", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Arch.Types.hi64", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
[]
Vale.AES.GCM_helpers.lemma_mod_n_8_upper1
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures Vale.Arch.Types.hi64 q % Prims.pow2 (8 * n) == Mkfour?.hi2 q % Prims.pow2 (8 * n))
{ "end_col": 43, "end_line": 326, "start_col": 2, "start_line": 323 }
FStar.Pervasives.Lemma
val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); ()
val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) let lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) =
false
null
true
assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "FStar.Mul.op_Star", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Modulus", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.squash", "Prims.op_LessThan", "Prims.l_or", "Vale.Def.Words_s.pow2_64", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
[]
Vale.AES.GCM_helpers.lemma_64_32_hi1
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q': Vale.Def.Types_s.quad32 -> hi: Vale.Def.Types_s.nat64 -> hi': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ hi' == hi % Prims.pow2 (8 * n) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words_s.Mktwo (Mkfour?.lo0 q') (Mkfour?.lo1 q')) (Vale.Def.Words.Two_s.nat_to_two 32 hi')) (ensures hi' < 0x100000000 /\ hi' == Mkfour?.hi2 q' /\ Mkfour?.hi3 q' == 0)
{ "end_col": 4, "end_line": 385, "start_col": 2, "start_line": 379 }
FStar.Pervasives.Lemma
val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); ()
val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) let lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) =
false
null
true
assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "FStar.Mul.op_Star", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Modulus", "Prims.op_Addition", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
[]
Vale.AES.GCM_helpers.lemma_64_32_hi2
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q': Vale.Def.Types_s.quad32 -> hi: Vale.Def.Types_s.nat64 -> hi': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ hi' == hi % Prims.pow2 (8 * (n + 4)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words_s.Mktwo (Mkfour?.lo0 q') (Mkfour?.lo1 q')) (Vale.Def.Words.Two_s.nat_to_two 32 hi')) (ensures hi' == Mkfour?.hi2 q' + 0x100000000 * Mkfour?.hi3 q')
{ "end_col": 4, "end_line": 401, "start_col": 2, "start_line": 395 }
FStar.Pervasives.Lemma
val lemma_mod_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); ()
val lemma_mod_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) let lemma_mod_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) =
false
null
true
lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.op_LessThanOrEqual", "Vale.AES.GCM_helpers.lemma_mod_n_8_lower2_helper", "Prims.bool", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.logical", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Arch.Types.lo64_def", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Arch.Types.lo64_reveal", "Prims.squash", "Vale.Arch.Types.lo64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
[]
Vale.AES.GCM_helpers.lemma_mod_n_8_lower2
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures Vale.Arch.Types.lo64 q % Prims.pow2 (8 * (4 + n)) == Mkfour?.lo0 q + 0x100000000 * (Mkfour?.lo1 q % Prims.pow2 (8 * n)))
{ "end_col": 4, "end_line": 317, "start_col": 2, "start_line": 311 }
FStar.Pervasives.Lemma
val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) let lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) =
false
null
true
assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "FStar.Mul.op_Star", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Modulus", "Prims.op_Addition", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.four", "Vale.Def.Words_s.Mkfour", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
[]
Vale.AES.GCM_helpers.lemma_64_32_lo2
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q': Vale.Def.Types_s.quad32 -> lo: Vale.Def.Types_s.nat64 -> lo': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ lo' == lo % Prims.pow2 (8 * (n + 4)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo') (Vale.Def.Words.Two_s.nat_to_two 32 0)) (ensures lo' == Mkfour?.lo0 q' + 0x100000000 * Mkfour?.lo1 q' /\ q' == Vale.Def.Words_s.Mkfour (Mkfour?.lo0 q') (Mkfour?.lo1 q') 0 0)
{ "end_col": 4, "end_line": 369, "start_col": 2, "start_line": 362 }
FStar.Pervasives.Lemma
val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) let lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) =
false
null
true
assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "FStar.Mul.op_Star", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Modulus", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Prims.squash", "Prims.op_LessThan", "Prims.l_or", "Vale.Def.Words_s.pow2_64", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.four", "Vale.Def.Words_s.Mkfour", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
[]
Vale.AES.GCM_helpers.lemma_64_32_lo1
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q': Vale.Def.Types_s.quad32 -> lo: Vale.Def.Types_s.nat64 -> lo': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ lo' == lo % Prims.pow2 (8 * n) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo') (Vale.Def.Words.Two_s.nat_to_two 32 0)) (ensures lo' < 0x100000000 /\ lo' == Mkfour?.lo0 q' /\ q' == Vale.Def.Words_s.Mkfour (Mkfour?.lo0 q') 0 0 0)
{ "end_col": 4, "end_line": 352, "start_col": 2, "start_line": 345 }
FStar.Pervasives.Lemma
val lemma_mod_n_8_lower2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); ()
val lemma_mod_n_8_lower2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) let lemma_mod_n_8_lower2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) =
false
null
true
lo64_reveal (); let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.logical", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Arch.Types.lo64_def", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Arch.Types.lo64_reveal", "Prims.squash", "Vale.Arch.Types.lo64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_n_8_lower2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
[]
Vale.AES.GCM_helpers.lemma_mod_n_8_lower2_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 2) (ensures Vale.Arch.Types.lo64 q % Prims.pow2 (8 * (4 + n)) == Mkfour?.lo0 q + 0x100000000 * (Mkfour?.lo1 q % Prims.pow2 (8 * n)))
{ "end_col": 4, "end_line": 305, "start_col": 2, "start_line": 299 }
FStar.Pervasives.Lemma
val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) )
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); ()
val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) ) let lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) ) =
false
null
true
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Types_s.nat8", "Prims.nat", "Prims.unit", "Prims._assert", "Prims.l_imp", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.natN", "Prims.op_Multiply", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_LE", "FStar.Pervasives.assert_norm", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.op_LessThanOrEqual", "Vale.AES.GCM_helpers.lemma_pad_to_32_bits_helper", "Prims.bool", "Prims.l_or", "Prims.l_and", "Prims.b2t", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) )
[]
Vale.AES.GCM_helpers.lemma_pad_to_32_bits
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ (forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i} i < 4 ==> FStar.Seq.Base.index s'' i == (match i < n with | true -> FStar.Seq.Base.index s i | _ -> 0))) (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s'') == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s) % Prims.pow2 (8 * n))
{ "end_col": 4, "end_line": 279, "start_col": 2, "start_line": 267 }
FStar.Pervasives.Lemma
val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) )
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); ()
val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) ) let lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) ) =
false
null
true
assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Types_s.nat8", "Prims.nat", "Prims.unit", "Prims._assert", "Prims.l_imp", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.natN", "Prims.op_Multiply", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_LE", "FStar.Pervasives.assert_norm", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.l_or", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Prims.bool", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n) )
[]
Vale.AES.GCM_helpers.lemma_pad_to_32_bits_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 2 /\ (forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i} i < 4 ==> FStar.Seq.Base.index s'' i == (match i < n with | true -> FStar.Seq.Base.index s i | _ -> 0))) (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s'') == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s) % Prims.pow2 (8 * n))
{ "end_col": 4, "end_line": 257, "start_col": 2, "start_line": 245 }
FStar.Pervasives.Lemma
val lemma_slices_le_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); le_bytes_to_quad32_reveal (); ()
val lemma_slices_le_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)))) let lemma_slices_le_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)))) =
false
null
true
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); le_bytes_to_quad32_reveal (); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Words.Seq_s.seq16", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.Def.Types_s.le_bytes_to_quad32_reveal", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Def.Words_s.four", "Prims.op_Division", "Vale.Def.Words.Seq_s.seq_to_seq_four_LE", "Prims.l_True", "Prims.squash", "Prims.l_and", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_LE", "FStar.Seq.Base.slice", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.le_bytes_to_quad32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) ))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_slices_le_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))))
[]
Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (ensures (let q = Vale.Def.Types_s.le_bytes_to_quad32 s in Mkfour?.lo0 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 0 4)) /\ Mkfour?.lo1 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 4 8)) /\ Mkfour?.hi2 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 8 12)) /\ Mkfour?.hi3 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 12 16))))
{ "end_col": 4, "end_line": 414, "start_col": 2, "start_line": 412 }
FStar.Pervasives.Lemma
val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_hi = (hi64 q) % pow2 ((num_bytes - 8) * 8) in new_hi < pow2_64 /\ (let q' = insert_nat64 q new_hi 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)))))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pad_to_128_bits_upper (q:quad32) (num_bytes:int) = let n = num_bytes in let new_hi = (hi64 q) % pow2 ((n - 8) * 8) in pow2_lt_compat 64 ((n - 8) * 8); let s = le_quad32_to_bytes q in let s' = slice s 0 n in let q' = insert_nat64_def q new_hi 1 in insert_nat64_reveal (); let s'' = pad_to_128_bits s' in let q'' = le_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 12 then ( lemma_mod_n_8_upper1 q (n - 8); lemma_64_32_hi1 q' (hi64 q) new_hi (n - 8); lemma_pad_to_32_bits s8_12 s8_12'' (n - 8); () ) else ( lemma_mod_n_8_upper2 q (n - 12); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 12); lemma_pad_to_32_bits s12_16 s12_16'' (n - 12); () ); lemma_slices_le_quad32_to_bytes q; lemma_slices_le_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 12 ==> equal s12_16'' zero_4); ()
val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_hi = (hi64 q) % pow2 ((num_bytes - 8) * 8) in new_hi < pow2_64 /\ (let q' = insert_nat64 q new_hi 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) let pad_to_128_bits_upper (q: quad32) (num_bytes: int) =
false
null
true
let n = num_bytes in let new_hi = (hi64 q) % pow2 ((n - 8) * 8) in pow2_lt_compat 64 ((n - 8) * 8); let s = le_quad32_to_bytes q in let s' = slice s 0 n in let q' = insert_nat64_def q new_hi 1 in insert_nat64_reveal (); let s'' = pad_to_128_bits s' in let q'' = le_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 12 then (lemma_mod_n_8_upper1 q (n - 8); lemma_64_32_hi1 q' (hi64 q) new_hi (n - 8); lemma_pad_to_32_bits s8_12 s8_12'' (n - 8); ()) else (lemma_mod_n_8_upper2 q (n - 12); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 12); lemma_pad_to_32_bits s12_16 s12_16'' (n - 12); ()); lemma_slices_le_quad32_to_bytes q; lemma_slices_le_bytes_to_quad32 s''; lemma_four_zero (); let zero_4:seq nat8 = create 4 0 in assert (n < 12 ==> equal s12_16'' zero_4); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.int", "Vale.Def.Types_s.nat32", "Prims.unit", "Prims._assert", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Vale.AES.GCM_helpers.lemma_four_zero", "Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32", "Vale.AES.Types_helpers.lemma_slices_le_quad32_to_bytes", "Vale.AES.GCM_helpers.lemma_pad_to_32_bits", "Prims.op_Subtraction", "Vale.AES.GCM_helpers.lemma_64_32_hi1", "Vale.Arch.Types.hi64", "Vale.AES.GCM_helpers.lemma_mod_n_8_upper1", "Prims.bool", "Vale.AES.GCM_helpers.lemma_64_32_hi2", "Vale.AES.GCM_helpers.lemma_mod_n_8_upper2", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.Def.Types_s.insert_nat64_reveal", "Vale.Def.Types_s.insert_nat64_def", "Vale.Def.Types_s.le_quad32_to_bytes", "FStar.Math.Lemmas.pow2_lt_compat", "FStar.Mul.op_Star", "Prims.op_Modulus", "Prims.pow2" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); le_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); () let pad_to_128_bits_lower (q:quad32) (num_bytes:int) = let n = num_bytes in let new_lo = (lo64 q) % pow2 (n * 8) in pow2_lt_compat 64 (n * 8); let s = le_quad32_to_bytes q in let s' = slice s 0 n in let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in insert_nat64_reveal (); let s'' = pad_to_128_bits s' in let q'' = le_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 4 then ( lemma_mod_n_8_lower1 q n; lemma_64_32_lo1 q' (lo64 q) new_lo n; lemma_pad_to_32_bits s0_4 s0_4'' n; () ) else ( lemma_mod_n_8_lower2 q (n - 4); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); () ); lemma_slices_le_quad32_to_bytes q; lemma_slices_le_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); ()
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_hi = (hi64 q) % pow2 ((num_bytes - 8) * 8) in new_hi < pow2_64 /\ (let q' = insert_nat64 q new_hi 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)))))
[]
Vale.AES.GCM_helpers.pad_to_128_bits_upper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_hi = Vale.Arch.Types.hi64 q % Prims.pow2 ((num_bytes - 8) * 8) in new_hi < Vale.Def.Words_s.pow2_64 /\ (let q' = Vale.Def.Types_s.insert_nat64 q new_hi 1 in q' == Vale.Def.Types_s.le_bytes_to_quad32 (Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes q) 0 num_bytes)))))
{ "end_col": 4, "end_line": 517, "start_col": 54, "start_line": 472 }
FStar.Pervasives.Lemma
val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_lo = (lo64 q) % pow2 (num_bytes * 8) in new_lo < pow2_64 /\ (let q' = insert_nat64 (insert_nat64 q 0 1) new_lo 0 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)))))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pad_to_128_bits_lower (q:quad32) (num_bytes:int) = let n = num_bytes in let new_lo = (lo64 q) % pow2 (n * 8) in pow2_lt_compat 64 (n * 8); let s = le_quad32_to_bytes q in let s' = slice s 0 n in let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in insert_nat64_reveal (); let s'' = pad_to_128_bits s' in let q'' = le_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 4 then ( lemma_mod_n_8_lower1 q n; lemma_64_32_lo1 q' (lo64 q) new_lo n; lemma_pad_to_32_bits s0_4 s0_4'' n; () ) else ( lemma_mod_n_8_lower2 q (n - 4); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); () ); lemma_slices_le_quad32_to_bytes q; lemma_slices_le_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); ()
val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_lo = (lo64 q) % pow2 (num_bytes * 8) in new_lo < pow2_64 /\ (let q' = insert_nat64 (insert_nat64 q 0 1) new_lo 0 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) let pad_to_128_bits_lower (q: quad32) (num_bytes: int) =
false
null
true
let n = num_bytes in let new_lo = (lo64 q) % pow2 (n * 8) in pow2_lt_compat 64 (n * 8); let s = le_quad32_to_bytes q in let s' = slice s 0 n in let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in insert_nat64_reveal (); let s'' = pad_to_128_bits s' in let q'' = le_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 4 then (lemma_mod_n_8_lower1 q n; lemma_64_32_lo1 q' (lo64 q) new_lo n; lemma_pad_to_32_bits s0_4 s0_4'' n; ()) else (lemma_mod_n_8_lower2 q (n - 4); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); ()); lemma_slices_le_quad32_to_bytes q; lemma_slices_le_bytes_to_quad32 s''; lemma_four_zero (); let zero_4:seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.int", "Vale.Def.Types_s.nat32", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Vale.AES.GCM_helpers.lemma_four_zero", "Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32", "Vale.AES.Types_helpers.lemma_slices_le_quad32_to_bytes", "Vale.AES.GCM_helpers.lemma_pad_to_32_bits", "Vale.AES.GCM_helpers.lemma_64_32_lo1", "Vale.Arch.Types.lo64", "Vale.AES.GCM_helpers.lemma_mod_n_8_lower1", "Prims.bool", "Prims.op_Subtraction", "Vale.AES.GCM_helpers.lemma_64_32_lo2", "Vale.AES.GCM_helpers.lemma_mod_n_8_lower2", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.Def.Types_s.insert_nat64_reveal", "Vale.Def.Types_s.insert_nat64_def", "Vale.Def.Types_s.le_quad32_to_bytes", "FStar.Math.Lemmas.pow2_lt_compat", "FStar.Mul.op_Star", "Prims.op_Modulus", "Prims.pow2" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) = lo64_reveal (); if n <= 2 then lemma_mod_n_8_lower2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) = hi64_reveal (); lo64_reveal (); let Mkfour _ _ q2 q3 = q in lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * n) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) = assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\ four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi') ) (ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) = assert_norm (pow2 (4 * 8) == 0x100000000); assert_norm (pow2 (5 * 8) == 0x10000000000); assert_norm (pow2 (6 * 8) == 0x1000000000000); assert_norm (pow2 (7 * 8) == 0x100000000000000); assert_norm (pow2 (8 * 8) == 0x10000000000000000); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); () let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = le_bytes_to_quad32 s in q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\ q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\ q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\ q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); le_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); ()
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_lo = (lo64 q) % pow2 (num_bytes * 8) in new_lo < pow2_64 /\ (let q' = insert_nat64 (insert_nat64 q 0 1) new_lo 0 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)))))
[]
Vale.AES.GCM_helpers.pad_to_128_bits_lower
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_lo = Vale.Arch.Types.lo64 q % Prims.pow2 (num_bytes * 8) in new_lo < Vale.Def.Words_s.pow2_64 /\ (let q' = Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 q 0 1) new_lo 0 in q' == Vale.Def.Types_s.le_bytes_to_quad32 (Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes q) 0 num_bytes)))))
{ "end_col": 4, "end_line": 470, "start_col": 54, "start_line": 423 }
FStar.Pervasives.Lemma
val le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) : Lemma(let Mkfour q0 q1 q2 q3 = q in (i < 4 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q0) (i % 4)) /\ (4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q1) (i % 4)) /\ (8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q2) (i % 4)) /\ (12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q3) (i % 4)))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
val le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) : Lemma(let Mkfour q0 q1 q2 q3 = q in (i < 4 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q0) (i % 4)) /\ (4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q1) (i % 4)) /\ (8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q2) (i % 4)) /\ (12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q3) (i % 4))) let le_quad32_to_bytes_sel (q: quad32) (i: nat{i < 16}) =
false
null
true
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert (i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert (4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert (8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert (12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm [ primops; delta_only [ `%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE ] ]; dump " after norm2"); assert (i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert (4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4) ); assert (8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert (12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.natN", "Prims.pow2", "Prims._assert", "Prims.l_imp", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.eq2", "FStar.Seq.Base.index", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Words.Four_s.four_select", "Vale.Def.Words.Four_s.nat_to_four", "Prims.op_Modulus", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.op_Equality", "FStar.Seq.Base.init", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.Def.Words_s.four", "Vale.Def.Words.Seq_s.four_to_seq_LE", "Prims.op_Division", "FStar.Tactics.V1.Builtins.dump", "FStar.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.primops", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Prims.l_True", "Prims.int" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "native", "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", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3", "smt.arith.nl=true" ], "z3refresh": false, "z3rlimit": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) : Lemma(let Mkfour q0 q1 q2 q3 = q in (i < 4 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q0) (i % 4)) /\ (4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q1) (i % 4)) /\ (8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q2) (i % 4)) /\ (12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q3) (i % 4)))
[]
Vale.AES.GCM_helpers.le_quad32_to_bytes_sel
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> i: Prims.nat{i < 16} -> FStar.Pervasives.Lemma (ensures (let _ = q in (let { lo0 = q0 ; lo1 = q1 ; hi2 = q2 ; hi3 = q3 } = _ in (i < 4 ==> FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i = Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q0) (i % 4)) /\ (4 <= i /\ i < 8 ==> FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i = Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q1) (i % 4)) /\ (8 <= i /\ i < 12 ==> FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i = Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q2) (i % 4)) /\ (12 <= i /\ i < 16 ==> FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i = Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q3) (i % 4))) <: Type0))
{ "end_col": 104, "end_line": 233, "start_col": 2, "start_line": 152 }
FStar.Pervasives.Lemma
val lemma_mod_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) = lo64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); ()
val lemma_mod_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) let lemma_mod_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) =
false
null
true
lo64_reveal (); let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); ()
{ "checked_file": "Vale.AES.GCM_helpers.fst.checked", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers.fst" }
[ "lemma" ]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.logical", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Arch.Types.lo64_def", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Arch.Types.lo64_reveal", "Prims.squash", "Vale.Arch.Types.lo64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM_helpers open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_s open Vale.AES.GCTR_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let extra_bytes_helper (n:nat) : Lemma (requires n % 16 <> 0) (ensures bytes_to_quad_size n == n / 16 + 1) = () #reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1" let bytes_to_quad_size_no_extra_bytes num_bytes = () let no_extra_bytes_helper s num_bytes = slice_length (le_seq_quad32_to_bytes s) let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in let x' = slice (le_quad32_to_bytes final) 0 num_extra in le_seq_quad32_to_bytes_of_singleton final; assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final)); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra); slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes); assert (equal x' x); () let index_helper (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks)) = () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in // Need to show that full_bytes == le_seq_quad32_to_bytes full_quads // Need to show that le_quad32_to_bytes final_quad == partial_bytes // full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks // This should be from slice_slice // == slice (le_seq_quad32_bot_bytes s) 0 full_blocks // == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16) // This follows from slice_commutes_le_seq_quad32_to_bytes0 // le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks) slice_commutes_le_seq_quad32_to_bytes0 s num_blocks; // ==> (* assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) == le_seq_quad32_to_bytes (slice s 0 num_blocks)); *) slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks; assert (full_bytes == le_seq_quad32_to_bytes full_quads); // slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra // F* believes assert (final_quad == index s num_blocks), so we have: // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // // == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra // from le_seq_quad32_to_bytes_tail_prefix // == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes // == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes // From slice_slice // partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes; le_seq_quad32_to_bytes_tail_prefix s num_bytes; () (* let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16) (ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes))) = () let insert_0_is_padding (q:quad32) : Lemma (let q' = insert_nat64_def q 0 1 in q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8))) = () *) #reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10" let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) = reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes; let Mkfour q0 q1 q2 q3 = q in assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2); assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3); let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33) (fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]); assert(i < 4 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4)) i == four_select (nat_to_four 8 q3) (i % 4)); assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i = (index (init (length (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) * 4) (fun n -> four_select (index (init (length (four_to_seq_LE q)) (fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) (n / 4)) (n % 4))) i)) (fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes; `%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose; `%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2"); assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i); assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)); assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4)); assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1); assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100); assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s)); assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_LE s'') in assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000); assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000); () let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
false
false
Vale.AES.GCM_helpers.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
[]
Vale.AES.GCM_helpers.lemma_mod_n_8_lower1
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures Vale.Arch.Types.lo64 q % Prims.pow2 (8 * n) == Mkfour?.lo0 q % Prims.pow2 (8 * n))
{ "end_col": 4, "end_line": 293, "start_col": 2, "start_line": 285 }
Prims.Tot
val mk_bn_mod_inv_prime_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len -> bn_mod_inv_prime_ctx_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_bn_mod_inv_prime_ctx #t len bn_mod_inv_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_inv_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
val mk_bn_mod_inv_prime_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len -> bn_mod_inv_prime_ctx_st t len let mk_bn_mod_inv_prime_ctx #t len bn_mod_inv_precomp k a res =
false
null
false
let open LowStar.BufferOps in let k1 = !*k in bn_mod_inv_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Ghost.erased", "Hacl.Bignum.meta_len", "Hacl.Bignum.ModInv.bn_mod_inv_prime_precomp_st", "FStar.Ghost.reveal", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2", "Prims.unit", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) inline_for_extraction noextract val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len let bn_mod_ctx #t len bn_mod_slow_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res inline_for_extraction noextract let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> bBits:size_t -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\ bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) inline_for_extraction noextract val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res inline_for_extraction noextract let bn_mod_inv_prime_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ 0 < bn_v h a /\ bn_v h a < MA.bn_v_n h k /\ FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1) inline_for_extraction noextract val mk_bn_mod_inv_prime_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len -> bn_mod_inv_prime_ctx_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bn_mod_inv_prime_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len -> bn_mod_inv_prime_ctx_st t len
[]
Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_ctx
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) -> bn_mod_inv_precomp: Hacl.Bignum.ModInv.bn_mod_inv_prime_precomp_st t (FStar.Ghost.reveal len) -> Hacl.Bignum.SafeAPI.bn_mod_inv_prime_ctx_st t (FStar.Ghost.reveal len)
{ "end_col": 52, "end_line": 324, "start_col": 2, "start_line": 322 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_inv_prime_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ 0 < bn_v h a /\ bn_v h a < MA.bn_v_n h k /\ FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1)
let bn_mod_inv_prime_ctx_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
k: MA.pbn_mont_ctx t -> a: lbignum t len -> res: lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ 0 < bn_v h a /\ bn_v h a < MA.bn_v_n h k /\ FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1)
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "LowStar.Monotonic.Buffer.deref", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.Buffer.trivial_preorder", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv", "Prims.b2t", "Prims.op_LessThan", "Hacl.Bignum.Definitions.bn_v", "Hacl.Bignum.MontArithmetic.bn_v_n", "FStar.Math.Euclid.is_prime", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Bignum.MontArithmetic.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.buffer", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) inline_for_extraction noextract val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len let bn_mod_ctx #t len bn_mod_slow_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res inline_for_extraction noextract let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> bBits:size_t -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\ bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) inline_for_extraction noextract val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_inv_prime_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_inv_prime_ctx_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 49, "end_line": 311, "start_col": 4, "start_line": 297 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
let bn_mod_inv_prime_safe_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
n: lbignum t len -> a: lbignum t len -> res: lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.Math.Euclid.is_prime", "Hacl.Bignum.Definitions.bn_v", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Hacl.Spec.Bignum.ModInv.bn_check_mod_inv_prime", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Prims.l_imp", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_inv_prime_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_inv_prime_safe_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 51, "end_line": 207, "start_col": 4, "start_line": 198 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
let new_bn_from_bytes_be_st (t: limb_t) =
false
null
false
r: HS.rid -> len: size_t -> b: lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> (0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Monotonic.HyperHeap.rid", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "LowStar.Buffer.buffer", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "FStar.HyperStack.ST.is_eternal_region", "Prims.l_imp", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.trivial_preorder", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Prims.eq2", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_region_only", "Lib.Sequence.seq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Hacl.Spec.Bignum.Definitions.blocks", "Lib.Buffer.as_seq", "Hacl.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Convert.bn_from_bytes_be" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract
false
true
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val new_bn_from_bytes_be_st : t: Hacl.Bignum.Definitions.limb_t -> Type0
[]
Hacl.Bignum.SafeAPI.new_bn_from_bytes_be_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> Type0
{ "end_col": 114, "end_line": 53, "start_col": 4, "start_line": 39 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
let new_bn_from_bytes_le_st (t: limb_t) =
false
null
false
r: HS.rid -> len: size_t -> b: lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> (0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Monotonic.HyperHeap.rid", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "LowStar.Buffer.buffer", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "FStar.HyperStack.ST.is_eternal_region", "Prims.l_imp", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.trivial_preorder", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.numbytes", "Hacl.Bignum.Definitions.blocks", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Prims.eq2", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_region_only", "Lib.Sequence.seq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Hacl.Spec.Bignum.Definitions.blocks", "Lib.Buffer.as_seq", "Hacl.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Convert.bn_from_bytes_le" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract
false
true
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val new_bn_from_bytes_le_st : t: Hacl.Bignum.Definitions.limb_t -> Type0
[]
Hacl.Bignum.SafeAPI.new_bn_from_bytes_le_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> Type0
{ "end_col": 114, "end_line": 97, "start_col": 4, "start_line": 83 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
let bn_mod_slow_safe_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
n: lbignum t len -> a: lbignum t (len +! len) -> res: lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Hacl.Spec.Bignum.Montgomery.bn_check_modulus", "Lib.IntTypes.v", "Lib.Buffer.as_seq", "Prims.l_imp", "Prims.b2t", "Prims.int", "Hacl.Bignum.Definitions.bn_v", "Prims.op_Modulus" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_slow_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_slow_safe_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 49, "end_line": 136, "start_col": 4, "start_line": 127 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
let bn_mod_slow_ctx_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
k: MA.pbn_mont_ctx t -> a: lbignum t (len +! len) -> res: lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "LowStar.Monotonic.Buffer.deref", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.Buffer.trivial_preorder", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Bignum.MontArithmetic.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.buffer", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.int", "Hacl.Bignum.Definitions.bn_v", "Prims.op_Modulus", "Hacl.Bignum.MontArithmetic.bn_v_n" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_slow_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_slow_ctx_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 46, "end_line": 243, "start_col": 4, "start_line": 232 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
let bn_mod_exp_safe_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
n: lbignum t len -> a: lbignum t len -> bBits: size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b: lbignum t (blocks0 bBits (size (bits t))) -> res: lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.blocks0", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Prims.bool", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Hacl.Spec.Bignum.Exponentiation.bn_check_mod_exp", "Lib.Buffer.as_seq", "Prims.l_imp", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_exp_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 99, "end_line": 172, "start_col": 4, "start_line": 161 }
Prims.Tot
val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_ctx #t len bn_mod_slow_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
false
null
false
let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Ghost.erased", "Hacl.Bignum.meta_len", "Hacl.Bignum.ModReduction.bn_mod_slow_precomp_st", "FStar.Ghost.reveal", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2", "Prims.unit", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) inline_for_extraction noextract val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len
[]
Hacl.Bignum.SafeAPI.bn_mod_ctx
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) -> bn_mod_slow_precomp: Hacl.Bignum.ModReduction.bn_mod_slow_precomp_st t (FStar.Ghost.reveal len) -> Hacl.Bignum.SafeAPI.bn_mod_slow_ctx_st t (FStar.Ghost.reveal len)
{ "end_col": 53, "end_line": 256, "start_col": 2, "start_line": 254 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> bBits:size_t -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\ bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
let bn_mod_exp_ctx_st (t: limb_t) (len: BN.meta_len t) =
false
null
false
k: MA.pbn_mont_ctx t -> a: lbignum t len -> bBits: size_t -> b: lbignum t (blocks0 bBits (size (bits t))) -> res: lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\ bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.blocks0", "Lib.IntTypes.size", "Lib.IntTypes.bits", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "LowStar.Monotonic.Buffer.deref", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.Buffer.trivial_preorder", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv", "Prims.b2t", "Prims.op_LessThan", "Hacl.Bignum.Definitions.bn_v", "Hacl.Bignum.MontArithmetic.bn_v_n", "Prims.pow2", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.disjoint", "LowStar.Monotonic.Buffer.loc_disjoint", "Hacl.Bignum.MontArithmetic.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.buffer", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post", "Lib.Buffer.as_seq", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) inline_for_extraction noextract val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len let bn_mod_ctx #t len bn_mod_slow_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res inline_for_extraction noextract
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bn_mod_exp_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
[]
Hacl.Bignum.SafeAPI.bn_mod_exp_ctx_st
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0
{ "end_col": 60, "end_line": 279, "start_col": 4, "start_line": 261 }
Prims.Tot
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b =
false
null
false
[@@ inline_let ]let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res:Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res:lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h2); res
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Monotonic.HyperHeap.rid", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_BarBar", "Prims.op_Equality", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Prims.op_Negation", "Lib.IntTypes.op_Less_Equals_Dot", "Lib.IntTypes.U32", "Hacl.Bignum.Definitions.blocks", "FStar.UInt32.div", "LowStar.Buffer.null", "Hacl.Bignum.Definitions.limb", "LowStar.Buffer.buffer", "Prims.bool", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowStar.Monotonic.Buffer.loc_none", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Bignum.Convert.mk_bn_from_bytes_le", "Hacl.Bignum.Definitions.lbignum", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.v", "Lib.Buffer.buffer_t", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.len", "LowStar.Monotonic.Buffer.is_null", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_imp", "LowStar.Monotonic.Buffer.g_is_null", "Prims.l_and", "Prims.nat", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "LowStar.Monotonic.Buffer.mmalloc_partial", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "LowStar.Monotonic.Buffer.lmbuffer_or_null", "Lib.IntTypes.int_t", "Lib.IntTypes.PUB", "Lib.IntTypes.size", "Lib.IntTypes.numbytes" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
[]
Hacl.Bignum.SafeAPI.new_bn_from_bytes_le
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Bignum.SafeAPI.new_bn_from_bytes_le_st t
{ "end_col": 9, "end_line": 122, "start_col": 2, "start_line": 103 }
Prims.Tot
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b =
false
null
false
[@@ inline_let ]let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res:Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res:lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in (let open B in modifies_only_not_unused_in loc_none h0 h2); res
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Monotonic.HyperHeap.rid", "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_BarBar", "Prims.op_Equality", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Prims.op_Negation", "Lib.IntTypes.op_Less_Equals_Dot", "Lib.IntTypes.U32", "Hacl.Bignum.Definitions.blocks", "FStar.UInt32.div", "LowStar.Buffer.null", "Hacl.Bignum.Definitions.limb", "LowStar.Buffer.buffer", "Prims.bool", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_only_not_unused_in", "LowStar.Monotonic.Buffer.loc_none", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Bignum.Convert.mk_bn_from_bytes_be", "Hacl.Bignum.Definitions.lbignum", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.v", "Lib.Buffer.buffer_t", "Lib.Buffer.MUT", "LowStar.Monotonic.Buffer.len", "LowStar.Monotonic.Buffer.is_null", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_imp", "LowStar.Monotonic.Buffer.g_is_null", "Prims.l_and", "Prims.nat", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "LowStar.Monotonic.Buffer.mmalloc_partial", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "LowStar.Monotonic.Buffer.lmbuffer_or_null", "Lib.IntTypes.int_t", "Lib.IntTypes.PUB", "Lib.IntTypes.size", "Lib.IntTypes.numbytes" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
[]
Hacl.Bignum.SafeAPI.new_bn_from_bytes_be
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Bignum.SafeAPI.new_bn_from_bytes_be_st t
{ "end_col": 9, "end_line": 78, "start_col": 2, "start_line": 59 }
Prims.Tot
val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
false
null
false
let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then (SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res) else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Exponentiation.bn_mod_exp_st", "Hacl.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Prims.bool", "Prims.unit", "Hacl.Bignum.ModInv.mk_bn_mod_inv_prime", "Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.memset", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Lib.IntTypes.bits", "Lib.IntTypes.range", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Spec.Bignum.Base.unsafe_size_from_limb", "Hacl.Spec.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Hacl.Bignum.Lib.bn_get_top_index", "Hacl.Bignum.ModInv.bn_check_mod_inv_prime", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len
[]
Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_safe
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Bignum.meta_len t -> bn_mod_exp: Hacl.Bignum.Exponentiation.bn_mod_exp_st t len -> Hacl.Bignum.SafeAPI.bn_mod_inv_prime_safe_st t len
{ "end_col": 35, "end_line": 227, "start_col": 56, "start_line": 217 }
Prims.Tot
val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res
val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res =
false
null
false
let open LowStar.BufferOps in let k1 = !*k in bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "FStar.Ghost.erased", "Hacl.Bignum.meta_len", "Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st", "FStar.Ghost.reveal", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.blocks0", "Lib.IntTypes.size", "Lib.IntTypes.bits", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n", "Hacl.Bignum.MontArithmetic.lb", "Hacl.Bignum.MontArithmetic.ll", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu", "Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2", "Prims.unit", "Hacl.Bignum.MontArithmetic.bn_mont_ctx", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> res:lbignum t len -> Stack bool (requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\ (r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) inline_for_extraction noextract val mk_bn_mod_inv_prime_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_inv_prime_safe_st t len let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res = let h0 = ST.get () in let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\ disjoint res a /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) inline_for_extraction noextract val bn_mod_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len -> bn_mod_slow_ctx_st t len let bn_mod_ctx #t len bn_mod_slow_precomp k a res = let open LowStar.BufferOps in let k1 = !*k in bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res inline_for_extraction noextract let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) = k:MA.pbn_mont_ctx t -> a:lbignum t len -> bBits:size_t -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack unit (requires fun h -> (B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\ bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t))))) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) inline_for_extraction noextract val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bn_mod_exp_ctx: #t:limb_t -> len:Ghost.erased _ -> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len -> bn_mod_exp_ctx_st t len
[]
Hacl.Bignum.SafeAPI.mk_bn_mod_exp_ctx
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) -> bn_mod_exp_precomp: Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (FStar.Ghost.reveal len) -> Hacl.Bignum.SafeAPI.bn_mod_exp_ctx_st t (FStar.Ghost.reveal len)
{ "end_col": 60, "end_line": 292, "start_col": 2, "start_line": 290 }
Prims.Tot
val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
false
null
false
let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then (SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res) else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.ModReduction.bn_mod_slow_st", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Prims.bool", "Prims.unit", "Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma", "Lib.IntTypes.v", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.memset", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Lib.IntTypes.bits", "Lib.IntTypes.range", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Spec.Bignum.Base.unsafe_size_from_limb", "Hacl.Spec.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Hacl.Bignum.Lib.bn_get_top_index", "Hacl.Bignum.Montgomery.bn_check_modulus", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len
[]
Hacl.Bignum.SafeAPI.mk_bn_mod_slow_safe
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Bignum.meta_len t -> bn_mod_slow: Hacl.Bignum.ModReduction.bn_mod_slow_st t len -> Hacl.Bignum.SafeAPI.bn_mod_slow_safe_st t len
{ "end_col": 35, "end_line": 156, "start_col": 52, "start_line": 146 }
Prims.Tot
val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.ModInv", "short_module": "SI" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Convert", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.Convert", "short_module": "BC" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Bignum.Lib", "short_module": "BL" }, { "abbrev": true, "full_module": "Hacl.Spec.Exponentiation.Lemmas", "short_module": "E" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res = let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
false
null
false
let h0 = ST.get () in let is_valid_m = exp_check n a bBits b in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then (SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_exp nBits n a bBits b res) else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m
{ "checked_file": "Hacl.Bignum.SafeAPI.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Exponentiation.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.ModInv.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Exponentiation.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.MontArithmetic.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.Base.fst.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Euclid.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.SafeAPI.fst" }
[ "total" ]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.meta_len", "Hacl.Bignum.Exponentiation.bn_check_mod_exp_st", "Hacl.Bignum.Exponentiation.bn_mod_exp_st", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.blocks0", "Lib.IntTypes.size", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Base.unsafe_bool_of_limb", "Prims.bool", "Prims.unit", "Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.memset", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.range", "Prims.op_Multiply", "Lib.IntTypes.mk_int", "Hacl.Spec.Bignum.Base.unsafe_size_from_limb", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Subtraction", "Prims.pow2", "Hacl.Bignum.Lib.bn_get_top_index", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Bignum.SafeAPI open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Definitions module ST = FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module LSeq = Lib.Sequence module E = Hacl.Spec.Exponentiation.Lemmas module BL = Hacl.Bignum.Lib module BB = Hacl.Bignum.Base module BN = Hacl.Bignum module MA = Hacl.Bignum.MontArithmetic module BM = Hacl.Bignum.Montgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BC = Hacl.Bignum.Convert module BI = Hacl.Bignum.ModInv module SL = Hacl.Spec.Bignum.Lib module SD = Hacl.Spec.Bignum.Definitions module SE = Hacl.Spec.Bignum.Exponentiation module SM = Hacl.Spec.Bignum.Montgomery module SC = Hacl.Spec.Bignum.Convert module SI = Hacl.Spec.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let new_bn_from_bytes_be_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t let new_bn_from_bytes_be #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_be false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let new_bn_from_bytes_le_st (t:limb_t) = r:HS.rid -> len:size_t -> b:lbuffer uint8 len -> ST (B.buffer (limb t)) (requires fun h -> live h b /\ ST.is_eternal_region r) (ensures fun h0 res h1 -> B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==> ( 0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\ B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\ B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\ as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) inline_for_extraction noextract val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t let new_bn_from_bytes_le #t r len b = [@inline_let] let numb = size (numbytes t) in if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then B.null else let h0 = ST.get () in let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in if B.is_null res then res else let h1 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h1); assert (B.len res == blocks len numb); let res: Lib.Buffer.buffer (limb t) = res in assert (B.length res == FStar.UInt32.v (blocks len numb)); let res: lbignum t (blocks len numb) = res in BC.mk_bn_from_bytes_le false len b res; let h2 = ST.get () in B.(modifies_only_not_unused_in loc_none h0 h2); res inline_for_extraction noextract let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t (len +! len) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\ (r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) inline_for_extraction noextract val mk_bn_mod_slow_safe: #t:limb_t -> len:BN.meta_len t -> bn_mod_slow:BR.bn_mod_slow_st t len -> bn_mod_slow_safe_st t len let mk_bn_mod_slow_safe #t len bn_mod_slow n a res = let h0 = ST.get () in let is_valid_m = BM.bn_check_modulus n in let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in if BB.unsafe_bool_of_limb is_valid_m then begin SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n); bn_mod_slow nBits n a res end else memset res (uint #t 0) len; BB.unsafe_bool_of_limb is_valid_m inline_for_extraction noextract let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) = n:lbignum t len -> a:lbignum t len -> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} -> b:lbignum t (blocks0 bBits (size (bits t))) -> res:lbignum t len -> Stack bool (requires fun h -> live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a) (ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\ r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\ (r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) inline_for_extraction noextract val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len
false
false
Hacl.Bignum.SafeAPI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_bn_mod_exp_safe: #t:limb_t -> len:BN.meta_len t -> exp_check:BE.bn_check_mod_exp_st t len -> bn_mod_exp:BE.bn_mod_exp_st t len -> bn_mod_exp_safe_st t len
[]
Hacl.Bignum.SafeAPI.mk_bn_mod_exp_safe
{ "file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Bignum.meta_len t -> exp_check: Hacl.Bignum.Exponentiation.bn_check_mod_exp_st t len -> bn_mod_exp: Hacl.Bignum.Exponentiation.bn_mod_exp_st t len -> Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st t len
{ "end_col": 35, "end_line": 193, "start_col": 68, "start_line": 183 }
Prims.Tot
val sealBase: sealBase_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp128 setupBaseS
val sealBase: sealBase_st cs True let sealBase =
false
null
false
hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp128 setupBaseS
{ "checked_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_sealBase_higher", "Hacl.HPKE.Curve51_CP128_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.AEAD.aead_encrypt_cp128", "Hacl.HPKE.Curve51_CP128_SHA256.setupBaseS" ]
[]
module Hacl.HPKE.Curve51_CP128_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51
false
true
Hacl.HPKE.Curve51_CP128_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sealBase: sealBase_st cs True
[]
Hacl.HPKE.Curve51_CP128_SHA256.sealBase
{ "file_name": "code/hpke/Hacl.HPKE.Curve51_CP128_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.sealBase_st Hacl.HPKE.Curve51_CP128_SHA256.cs Prims.l_True
{ "end_col": 80, "end_line": 18, "start_col": 15, "start_line": 18 }
Prims.Tot
val openBase: openBase_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let openBase = hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp128 setupBaseR
val openBase: openBase_st cs True let openBase =
false
null
false
hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp128 setupBaseR
{ "checked_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_openBase_higher", "Hacl.HPKE.Curve51_CP128_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.AEAD.aead_decrypt_cp128", "Hacl.HPKE.Curve51_CP128_SHA256.setupBaseR" ]
[]
module Hacl.HPKE.Curve51_CP128_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp128 setupBaseS
false
true
Hacl.HPKE.Curve51_CP128_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val openBase: openBase_st cs True
[]
Hacl.HPKE.Curve51_CP128_SHA256.openBase
{ "file_name": "code/hpke/Hacl.HPKE.Curve51_CP128_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.openBase_st Hacl.HPKE.Curve51_CP128_SHA256.cs Prims.l_True
{ "end_col": 80, "end_line": 20, "start_col": 15, "start_line": 20 }
Prims.Tot
val setupBaseS: setupBaseS_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256
val setupBaseS: setupBaseS_st cs True let setupBaseS =
false
null
false
hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256
{ "checked_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_setupBaseS_higher", "Hacl.HPKE.Curve51_CP128_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.HKDF.hkdf_expand256", "Hacl.HPKE.Interface.HKDF.hkdf_extract256", "Hacl.HPKE.Interface.DH.secret_to_public_c51", "Hacl.HPKE.Interface.DH.dh_c51" ]
[]
module Hacl.HPKE.Curve51_CP128_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0"
false
true
Hacl.HPKE.Curve51_CP128_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val setupBaseS: setupBaseS_st cs True
[]
Hacl.HPKE.Curve51_CP128_SHA256.setupBaseS
{ "file_name": "code/hpke/Hacl.HPKE.Curve51_CP128_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.setupBaseS_st Hacl.HPKE.Curve51_CP128_SHA256.cs Prims.l_True
{ "end_col": 162, "end_line": 14, "start_col": 17, "start_line": 14 }
Prims.Tot
val setupBaseR: setupBaseR_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51
val setupBaseR: setupBaseR_st cs True let setupBaseR =
false
null
false
hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51
{ "checked_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Curve51_CP128_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_setupBaseR_higher", "Hacl.HPKE.Curve51_CP128_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.HKDF.hkdf_expand256", "Hacl.HPKE.Interface.HKDF.hkdf_extract256", "Hacl.HPKE.Interface.DH.dh_c51", "Hacl.HPKE.Interface.DH.secret_to_public_c51" ]
[]
module Hacl.HPKE.Curve51_CP128_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_c51 IDH.dh_c51 IHK.hkdf_expand256 IHK.hkdf_extract256
false
true
Hacl.HPKE.Curve51_CP128_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val setupBaseR: setupBaseR_st cs True
[]
Hacl.HPKE.Curve51_CP128_SHA256.setupBaseR
{ "file_name": "code/hpke/Hacl.HPKE.Curve51_CP128_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.setupBaseR_st Hacl.HPKE.Curve51_CP128_SHA256.cs Prims.l_True
{ "end_col": 162, "end_line": 16, "start_col": 17, "start_line": 16 }
Prims.Tot
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let post_type t = mk_arrow (t, R.Q_Explicit) vprop_tm
let post_type t =
false
null
false
mk_arrow (t, R.Q_Explicit) vprop_tm
{ "checked_file": "Pulse.Soundness.STT.fsti.checked", "dependencies": [ "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Soundness.STT.fsti" }
[ "total" ]
[ "FStar.Reflection.Types.term", "Pulse.Reflection.Util.mk_arrow", "FStar.Pervasives.Native.Mktuple2", "FStar.Reflection.V2.Data.aqualv", "FStar.Reflection.V2.Data.Q_Explicit", "Pulse.Reflection.Util.vprop_tm" ]
[]
module Pulse.Soundness.STT module R = FStar.Reflection.V2 module RT = FStar.Reflection.Typing open Pulse.Reflection.Util
false
true
Pulse.Soundness.STT.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val post_type : t: FStar.Reflection.Types.term -> FStar.Reflection.Types.term
[]
Pulse.Soundness.STT.post_type
{ "file_name": "lib/steel/pulse/Pulse.Soundness.STT.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: FStar.Reflection.Types.term -> FStar.Reflection.Types.term
{ "end_col": 53, "end_line": 8, "start_col": 18, "start_line": 8 }
Prims.Tot
[ { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let inames_tm = R.(pack_ln (Tv_FVar (pack_fv inames_lid)))
let inames_tm =
false
null
false
let open R in pack_ln (Tv_FVar (pack_fv inames_lid))
{ "checked_file": "Pulse.Soundness.STT.fsti.checked", "dependencies": [ "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Soundness.STT.fsti" }
[ "total" ]
[ "FStar.Reflection.V2.Builtins.pack_ln", "FStar.Reflection.V2.Data.Tv_FVar", "FStar.Reflection.V2.Builtins.pack_fv", "Pulse.Reflection.Util.inames_lid" ]
[]
module Pulse.Soundness.STT module R = FStar.Reflection.V2 module RT = FStar.Reflection.Typing open Pulse.Reflection.Util
false
true
Pulse.Soundness.STT.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inames_tm : FStar.Reflection.Types.term
[]
Pulse.Soundness.STT.inames_tm
{ "file_name": "lib/steel/pulse/Pulse.Soundness.STT.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
FStar.Reflection.Types.term
{ "end_col": 57, "end_line": 9, "start_col": 19, "start_line": 9 }
Prims.Tot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qbuf a = (q:qual & qbuf_cases q a)
let qbuf a =
false
null
false
(q: qual & qbuf_cases q a)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "Prims.dtuple2", "LowStar.ConstBuffer.qual", "LowStar.ConstBuffer.qbuf_cases" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via
false
true
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qbuf : a: Type0 -> Type0
[]
LowStar.ConstBuffer.qbuf
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Type0 -> Type0
{ "end_col": 38, "end_line": 75, "start_col": 13, "start_line": 75 }
Prims.Tot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
let qbuf_pre (c: qbuf 'a) =
false
null
false
q_preorder (qbuf_qual c) 'a
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "LowStar.ConstBuffer.qbuf", "LowStar.ConstBuffer.q_preorder", "LowStar.ConstBuffer.qbuf_qual", "FStar.Preorder.preorder", "FStar.Seq.Base.seq" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qbuf_pre : c: LowStar.ConstBuffer.qbuf 'a -> FStar.Preorder.preorder (FStar.Seq.Base.seq 'a)
[]
LowStar.ConstBuffer.qbuf_pre
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.qbuf 'a -> FStar.Preorder.preorder (FStar.Seq.Base.seq 'a)
{ "end_col": 55, "end_line": 81, "start_col": 28, "start_line": 81 }
Prims.Tot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let live (h: HS.mem) (c: const_buffer 'a) =
false
null
false
B.live h (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.live", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val live : h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Type0
[]
LowStar.ConstBuffer.live
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Type0
{ "end_col": 65, "end_line": 107, "start_col": 45, "start_line": 107 }
Prims.Tot
val qual_of (#a: _) (c: const_buffer a) : Tot qual
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c)
val qual_of (#a: _) (c: const_buffer a) : Tot qual let qual_of (#a: _) (c: const_buffer a) : Tot qual =
false
null
false
dfst (as_qbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "LowStar.ConstBuffer.const_buffer", "FStar.Pervasives.dfst", "LowStar.ConstBuffer.qual", "LowStar.ConstBuffer.qbuf_cases", "LowStar.ConstBuffer.as_qbuf" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qual_of (#a: _) (c: const_buffer a) : Tot qual
[]
LowStar.ConstBuffer.qual_of
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer a -> LowStar.ConstBuffer.qual
{ "end_col": 20, "end_line": 99, "start_col": 4, "start_line": 99 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c)
let g_is_null (c: const_buffer 'a) =
false
null
false
B.g_is_null (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf", "Prims.bool" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c) let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val g_is_null : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.bool
[]
LowStar.ConstBuffer.g_is_null
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.bool
{ "end_col": 68, "end_line": 112, "start_col": 45, "start_line": 112 }
Prims.Tot
val qbuf_qual (c: qbuf 'a) : qual
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qbuf_qual (c:qbuf 'a) : qual = dfst c
val qbuf_qual (c: qbuf 'a) : qual let qbuf_qual (c: qbuf 'a) : qual =
false
null
false
dfst c
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "LowStar.ConstBuffer.qbuf", "FStar.Pervasives.dfst", "LowStar.ConstBuffer.qual", "LowStar.ConstBuffer.qbuf_cases" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qbuf_qual (c: qbuf 'a) : qual
[]
LowStar.ConstBuffer.qbuf_qual
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.qbuf 'a -> LowStar.ConstBuffer.qual
{ "end_col": 41, "end_line": 78, "start_col": 35, "start_line": 78 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let length (c: const_buffer 'a) =
false
null
false
B.length (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.length", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf", "Prims.nat" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val length : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.nat
[]
LowStar.ConstBuffer.length
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.nat
{ "end_col": 65, "end_line": 108, "start_col": 45, "start_line": 108 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c)
let as_seq (h: HS.mem) (c: const_buffer 'a) =
false
null
false
B.as_seq h (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.as_seq", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf", "FStar.Seq.Base.seq" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c) let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val as_seq : h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot (FStar.Seq.Base.seq 'a)
[]
LowStar.ConstBuffer.as_seq
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot (FStar.Seq.Base.seq 'a)
{ "end_col": 67, "end_line": 111, "start_col": 45, "start_line": 111 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
let loc_buffer (c: const_buffer 'a) =
false
null
false
B.loc_buffer (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf", "LowStar.Monotonic.Buffer.loc" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_buffer : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
[]
LowStar.ConstBuffer.loc_buffer
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
{ "end_col": 69, "end_line": 109, "start_col": 45, "start_line": 109 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c)
let loc_addr_of_buffer (c: const_buffer 'a) =
false
null
false
B.loc_addr_of_buffer (as_mbuf c)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.const_buffer", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "LowStar.ConstBuffer.as_mbuf", "LowStar.Monotonic.Buffer.loc" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val loc_addr_of_buffer : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
[]
LowStar.ConstBuffer.loc_addr_of_buffer
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
{ "end_col": 77, "end_line": 110, "start_col": 45, "start_line": 110 }
Prims.Tot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let const_sub_buffer (i:U32.t) (len:U32.t) (csub c:const_buffer 'a) = let qc = as_qbuf c in let qcsub = as_qbuf csub in U32.v i + U32.v len <= length c /\ csub == gsub c i len
let const_sub_buffer (i len: U32.t) (csub c: const_buffer 'a) =
false
null
false
let qc = as_qbuf c in let qcsub = as_qbuf csub in U32.v i + U32.v len <= length c /\ csub == gsub c i len
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "FStar.UInt32.t", "LowStar.ConstBuffer.const_buffer", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowStar.ConstBuffer.length", "Prims.eq2", "LowStar.ConstBuffer.gsub", "LowStar.ConstBuffer.qbuf", "LowStar.ConstBuffer.as_qbuf", "Prims.logical" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c) let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c) let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c) let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c) (*** CONSTRUCTORS **) /// `of_buffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_buffer (b:B.buffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == MUTABLE /\ qbuf_mbuf c == b) /// `of_ibuffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_ibuffer (b:I.ibuffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == IMMUTABLE /\ qbuf_mbuf c == b) /// `of_qbuf`: A constructors for const buffers from either mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a)) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == q /\ qbuf_mbuf c == b) /// null constant buffer let null 'a : const_buffer 'a = of_buffer B.null (*** OPERATIONS ON CONST POINTERS **) /// Is the buffer the null pointer? val is_null (c:const_buffer 'a) : Stack bool (requires (fun h -> live h c)) (ensures (fun h y h' -> h == h' /\ y == g_is_null c)) /// `index c i`: Very similar to the spec for `Buffer.index` val index (c:const_buffer 'a) (i:U32.t) : Stack 'a (requires fun h -> live h c /\ U32.v i < length c) (ensures fun h0 y h1 -> h0 == h1 /\ y == Seq.index (as_seq h0 c) (U32.v i)) /// Specification of sub let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a) = let qc = as_qbuf c in of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len)
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val const_sub_buffer : i: FStar.UInt32.t -> len: FStar.UInt32.t -> csub: LowStar.ConstBuffer.const_buffer 'a -> c: LowStar.ConstBuffer.const_buffer 'a -> Prims.logical
[]
LowStar.ConstBuffer.const_sub_buffer
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
i: FStar.UInt32.t -> len: FStar.UInt32.t -> csub: LowStar.ConstBuffer.const_buffer 'a -> c: LowStar.ConstBuffer.const_buffer 'a -> Prims.logical
{ "end_col": 22, "end_line": 183, "start_col": 69, "start_line": 179 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a
let qbuf_cases (q: qual) (a: Type) =
false
null
false
match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.qual", "LowStar.Buffer.buffer", "LowStar.ImmutableBuffer.ibuffer" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qbuf_cases : q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot Type0
[]
LowStar.ConstBuffer.qbuf_cases
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot Type0
{ "end_col": 28, "end_line": 61, "start_col": 2, "start_line": 59 }
Prims.Tot
val qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c)
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
val qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) let qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) =
false
null
false
dsnd c
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "total" ]
[ "LowStar.ConstBuffer.qbuf", "FStar.Pervasives.dsnd", "LowStar.ConstBuffer.qual", "LowStar.ConstBuffer.qbuf_cases", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.qbuf_pre" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c)
[]
LowStar.ConstBuffer.qbuf_mbuf
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.qbuf 'a -> LowStar.Monotonic.Buffer.mbuffer 'a (LowStar.ConstBuffer.qbuf_pre c) (LowStar.ConstBuffer.qbuf_pre c)
{ "end_col": 75, "end_line": 84, "start_col": 69, "start_line": 84 }
Prims.GTot
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a
let q_preorder (q: qual) (a: Type) =
false
null
false
match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.qual", "LowStar.Buffer.trivial_preorder", "LowStar.ImmutableBuffer.immutable_preorder", "LowStar.Monotonic.Buffer.srel" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val q_preorder : q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot (LowStar.Monotonic.Buffer.srel a)
[]
LowStar.ConstBuffer.q_preorder
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot (LowStar.Monotonic.Buffer.srel a)
{ "end_col": 39, "end_line": 70, "start_col": 2, "start_line": 68 }
Prims.GTot
val gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a)
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a) = let qc = as_qbuf c in of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len)
val gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a) let gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a) =
false
null
false
let qc = as_qbuf c in of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len)
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[ "sometrivial" ]
[ "LowStar.ConstBuffer.const_buffer", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowStar.ConstBuffer.length", "LowStar.ConstBuffer.of_qbuf", "LowStar.ConstBuffer.qbuf_qual", "LowStar.Monotonic.Buffer.mgsub", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.qbuf_mbuf", "LowStar.ConstBuffer.qbuf", "LowStar.ConstBuffer.as_qbuf" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c) let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c) let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c) let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c) (*** CONSTRUCTORS **) /// `of_buffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_buffer (b:B.buffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == MUTABLE /\ qbuf_mbuf c == b) /// `of_ibuffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_ibuffer (b:I.ibuffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == IMMUTABLE /\ qbuf_mbuf c == b) /// `of_qbuf`: A constructors for const buffers from either mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a)) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == q /\ qbuf_mbuf c == b) /// null constant buffer let null 'a : const_buffer 'a = of_buffer B.null (*** OPERATIONS ON CONST POINTERS **) /// Is the buffer the null pointer? val is_null (c:const_buffer 'a) : Stack bool (requires (fun h -> live h c)) (ensures (fun h y h' -> h == h' /\ y == g_is_null c)) /// `index c i`: Very similar to the spec for `Buffer.index` val index (c:const_buffer 'a) (i:U32.t) : Stack 'a (requires fun h -> live h c /\ U32.v i < length c) (ensures fun h0 y h1 -> h0 == h1 /\ y == Seq.index (as_seq h0 c) (U32.v i)) /// Specification of sub let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c})
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a)
[]
LowStar.ConstBuffer.gsub
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
c: LowStar.ConstBuffer.const_buffer 'a -> i: FStar.UInt32.t -> len: FStar.UInt32.t{FStar.UInt32.v i + FStar.UInt32.v len <= LowStar.ConstBuffer.length c} -> Prims.GTot (LowStar.ConstBuffer.const_buffer 'a)
{ "end_col": 56, "end_line": 176, "start_col": 3, "start_line": 175 }
FStar.HyperStack.ST.Stack
val test (x: B.buffer U32.t) (y: I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul)
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "I" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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 } ]
false
let test (x:B.buffer U32.t) (y:I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) = let c1 = of_buffer x in let c2 = of_ibuffer y in B.upd x 0ul 1ul; let a = index c1 0ul in assert (a == 1ul); let a' = index c2 0ul in assert (a' == 1ul); let c3 = sub c2 1ul 1ul in let a'' = index c3 0ul in assert (a'' == 2ul); U32.(a +^ a' +^ a'')
val test (x: B.buffer U32.t) (y: I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) let test (x: B.buffer U32.t) (y: I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) =
true
null
false
let c1 = of_buffer x in let c2 = of_ibuffer y in B.upd x 0ul 1ul; let a = index c1 0ul in assert (a == 1ul); let a' = index c2 0ul in assert (a' == 1ul); let c3 = sub c2 1ul 1ul in let a'' = index c3 0ul in assert (a'' == 2ul); let open U32 in a +^ a' +^ a''
{ "checked_file": "LowStar.ConstBuffer.fsti.checked", "dependencies": [ "prims.fst.checked", "LowStar.ImmutableBuffer.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "LowStar.ConstBuffer.fsti" }
[]
[ "LowStar.Buffer.buffer", "FStar.UInt32.t", "LowStar.ImmutableBuffer.ibuffer", "FStar.UInt32.op_Plus_Hat", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.UInt32.__uint_to_t", "LowStar.ConstBuffer.index", "LowStar.ConstBuffer.const_buffer", "LowStar.ConstBuffer.sub", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.upd", "LowStar.Buffer.trivial_preorder", "LowStar.ConstBuffer.of_ibuffer", "LowStar.ConstBuffer.of_buffer", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.ImmutableBuffer.immutable_preorder", "Prims.b2t", "Prims.op_GreaterThan", "LowStar.Monotonic.Buffer.length", "LowStar.Monotonic.Buffer.get", "LowStar.Monotonic.Buffer.disjoint", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.ConstBuffer (* This module provides a model of const pointers in C. A well-typed client guarantees that it will not mutate memory through a const pointer. But it cannot rely on the context not mutating the same memory. As such, we model const pointers as a finite disjunction of {mutable, immutable}-pointers, forcing code to guarantee the strongest condition of the two (immutability) and to rely only on the weakest (i.e., mutability). The main type of this module is `const_buffer t`. It is extracted by KaRaMeL to `const t*`. *) module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack open FStar.HyperStack.ST module I = LowStar.ImmutableBuffer module B = LowStar.Buffer (*** A model for const pointers **) /// We start by defining the finite disjunction of mutable and /// immutable buffers. /// /// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY /// The concrete type `const_buffer` is defined later /// `qual`: mutability qualifier [@@erasable] noeq type qual = | MUTABLE | IMMUTABLE /// `qbuf_cases q a`: disjunction of mutable and immutable pointers let qbuf_cases (q:qual) (a:Type) = match q with | MUTABLE -> B.buffer a | IMMUTABLE -> I.ibuffer a /// `q_preorder q a`: As we'll see shortly, it is convenient to also /// define a disjunction of the preorder indices on a qualified /// buffer inline_for_extraction let q_preorder (q:qual) (a:Type) = match q with | MUTABLE -> B.trivial_preorder a | IMMUTABLE -> I.immutable_preorder a /// `qbuf a`: This type is used for specificational purposes only. It /// is buffer whose mutability qualifier is existentially bound, via /// a dependent pair let qbuf a = (q:qual & qbuf_cases q a) /// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf` let qbuf_qual (c:qbuf 'a) : qual = dfst c /// `qbuf_pre c`: case-dependent preorders for a qbuf let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a /// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c (*** CONCRETE CONST POINTERS **) /// `const_buffer`: /// An abstract type of a read-only pointer to an array of `a` val const_buffer (a:Type u#0) : Type u#0 /// `as_qbuf`: For specificational purposes, a const_buffer can be /// seen as an existentially quantified qbuf val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) /// `qual_of`: let qual_of (#a:_) (c:const_buffer a) : Tot qual = dfst (as_qbuf c) /// `as_mbuf`: A convenience function to turn a const_buffer into a /// regular mbuffer, for spec purposes let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c) /// We now give several convenience functions that lift common /// notions on buffers to const_buffer, via the `as_mbuf` coercion let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) let length (c:const_buffer 'a) = B.length (as_mbuf c) let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c) let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c) let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c) (*** CONSTRUCTORS **) /// `of_buffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_buffer (b:B.buffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == MUTABLE /\ qbuf_mbuf c == b) /// `of_ibuffer`: A constructors for const buffers from mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_ibuffer (b:I.ibuffer 'a) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == IMMUTABLE /\ qbuf_mbuf c == b) /// `of_qbuf`: A constructors for const buffers from either mutable and /// immutable buffers. It is fully specified in terms of the /// `qbuf/mbuf` model val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a)) : Pure (const_buffer 'a) (requires True) (ensures fun c -> let c = as_qbuf c in qbuf_qual c == q /\ qbuf_mbuf c == b) /// null constant buffer let null 'a : const_buffer 'a = of_buffer B.null (*** OPERATIONS ON CONST POINTERS **) /// Is the buffer the null pointer? val is_null (c:const_buffer 'a) : Stack bool (requires (fun h -> live h c)) (ensures (fun h y h' -> h == h' /\ y == g_is_null c)) /// `index c i`: Very similar to the spec for `Buffer.index` val index (c:const_buffer 'a) (i:U32.t) : Stack 'a (requires fun h -> live h c /\ U32.v i < length c) (ensures fun h0 y h1 -> h0 == h1 /\ y == Seq.index (as_seq h0 c) (U32.v i)) /// Specification of sub let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c}) : GTot (const_buffer 'a) = let qc = as_qbuf c in of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len) /// Relational specification of sub let const_sub_buffer (i:U32.t) (len:U32.t) (csub c:const_buffer 'a) = let qc = as_qbuf c in let qcsub = as_qbuf csub in U32.v i + U32.v len <= length c /\ csub == gsub c i len /// `sub`: A sub-buffer of a const buffer points to a given /// within-bounds offset of its head val sub (#a:_) (c:const_buffer a) (i:U32.t) (len:Ghost.erased (U32.t)) : Stack (const_buffer a) (requires fun h -> live h c /\ U32.v i + U32.v len <= length c) (ensures fun h0 c' h1 -> let qc = as_qbuf c in let qc' = as_qbuf c' in h0 == h1 /\ c' `const_sub_buffer i len` c) /// Discussion between NS and JP (20191119) /// /// Why is it safe to generate C code that casts away the const qualifier with the /// cast operations below? Looking at the C11 standard, 6.7.3 alinea 6: /// /// > If an attempt is made to modify an object defined with a const-qualified type /// > through useof an lvalue with non-const-qualified type, the behavior is /// > undefined. /// /// So, dangerous things happen in situations where the original object is *created* /// with a const qualifier (the object's _identity_ is const). /// /// ``` /// #include <stdio.h> /// #include <stdlib.h> /// /// extern void f(const int *x); /// /// int main() { /// const int x = 0; /// f(&x); // f promises not to modify x /// printf("%d\n", x); // prints 0 at -O3 but 1 at -O0 /// return 0; /// } /// ``` /// /// with: /// /// ``` /// void f(const int *x) { /// int *y = (int *)x; /// *y = 1; /// } /// ``` /// /// In Low*, however, we never create objects that are marked const from the start. /// This is for historical reasons; in particular, immutable buffers are not marked /// const (they certainly could be). /// /// So, the casts seem to be safe? Also, the difference in behavior noted above /// does not happen if x is defined as /// /// ``` /// const int *x = calloc(1, sizeof *x); /// ``` /// /// Finally, the compiler, if the const qualifier is stripped from x, could still /// potentially rely on an argument of freshness (pointer provenance?) to deduce /// that &x is the sole pointer to x and that therefore the value of x should remain /// the same. This does not seem to be happening. /// `cast`: It is possible to cast away the const qualifier recovering /// a mutable or immutable pointer, in case the context can prove /// that `qbuf_qual c` is MUTABLE or IMMUTABLE, respectively val cast (c:const_buffer 'a) : Pure (B.mbuffer 'a (qbuf_pre (as_qbuf c)) (qbuf_pre (as_qbuf c))) (requires True) (ensures fun x -> x == as_mbuf c) val to_buffer (c:const_buffer 'a) : Pure (B.buffer 'a) (requires ( let c = as_qbuf c in qbuf_qual c == MUTABLE)) (ensures fun x -> x == as_mbuf c) val to_ibuffer (c:const_buffer 'a) : Pure (I.ibuffer 'a) (requires ( let c = as_qbuf c in qbuf_qual c == IMMUTABLE)) (ensures fun x -> x == as_mbuf c) //////////////////////////////////////////////////////////////////////////////// let test (x:B.buffer U32.t) (y:I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\
false
false
LowStar.ConstBuffer.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val test (x: B.buffer U32.t) (y: I.ibuffer U32.t) : Stack U32.t (requires fun h -> B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\ B.get h y 1 == 2ul /\ B.disjoint x y) (ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul)
[]
LowStar.ConstBuffer.test
{ "file_name": "ulib/LowStar.ConstBuffer.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
x: LowStar.Buffer.buffer FStar.UInt32.t -> y: LowStar.ImmutableBuffer.ibuffer FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 24, "end_line": 298, "start_col": 3, "start_line": 288 }
Prims.Tot
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash =
false
null
false
let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "total" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.word", "Hacl.Spec.SHA2.Vec.words_state'", "Lib.Sequence.create8", "Lib.IntTypes.op_Plus_Dot", "Spec.Hash.Definitions.word_t", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Hacl.Spec.SHA2._Sigma0", "Hacl.Spec.SHA2._Maj", "Hacl.Spec.SHA2._Sigma1", "Hacl.Spec.SHA2._Ch", "FStar.Seq.Base.index" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
[]
Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Hash.Definitions.sha2_alg -> k_t: Hacl.Spec.SHA2.Vec.word a -> ws_t: Hacl.Spec.SHA2.Vec.word a -> hash: Hacl.Spec.SHA2.Vec.words_state' a -> Hacl.Spec.SHA2.Vec.words_state' a
{ "end_col": 49, "end_line": 92, "start_col": 46, "start_line": 80 }
FStar.Pervasives.Lemma
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
false
null
true
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i: nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Lib.Sequence.eq_intro", "Prims.unit", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.index", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Pervasives.assert_norm", "Lib.Sequence.lseq", "Lib.Sequence.create8", "Prims.int", "Lib.Sequence.length", "FStar.Seq.Base.seq", "Prims.op_Equality", "FStar.List.Tot.Base.length", "Prims.Cons", "FStar.Seq.Base.length", "FStar.Seq.Properties.seq_of_list" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
[]
Hacl.Spec.SHA2.Equiv.seq_of_list_is_create8
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x0: a -> x1: a -> x2: a -> x3: a -> x4: a -> x5: a -> x6: a -> x7: a -> FStar.Pervasives.Lemma (ensures Lib.Sequence.create8 x0 x1 x2 x3 x4 x5 x6 x7 == FStar.Seq.Properties.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
{ "end_col": 16, "end_line": 76, "start_col": 55, "start_line": 67 }
FStar.Pervasives.Lemma
val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l =
false
null
true
ws_next_lemma_loop #a #m ws l 16
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.ws_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
[]
Hacl.Spec.SHA2.Equiv.ws_next_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.ws_next ws)).[ l ] == Hacl.Spec.SHA2.ws_next a (Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ])
{ "end_col": 65, "end_line": 183, "start_col": 33, "start_line": 183 }
FStar.Pervasives.Lemma
val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l
val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
false
null
true
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.num_rounds16", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.SHA2.Vec.ws_spec", "Hacl.Spec.SHA2.Vec.state_spec", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Equiv.ws_next_lemma_l", "Prims.unit", "Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
[]
Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} -> ws_st: (Hacl.Spec.SHA2.Vec.ws_spec a m * Hacl.Spec.SHA2.Vec.state_spec a m) -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.SHA2.Vec.shuffle_inner_loop i ws_st in (let FStar.Pervasives.Native.Mktuple2 #_ #_ ws1 st1 = _ in let _ = ws_st in (let FStar.Pervasives.Native.Mktuple2 #_ #_ ws0 st0 = _ in let _ = Hacl.Spec.SHA2.shuffle_inner_loop a i ((Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ], (Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ]) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ ws st = _ in (Hacl.Spec.SHA2.Vec.ws_spec_v ws1).[ l ] == ws /\ (Hacl.Spec.SHA2.Vec.state_spec_v st1).[ l ] == st) <: Type0) <: Type0) <: Type0))
{ "end_col": 23, "end_line": 249, "start_col": 2, "start_line": 248 }
FStar.Pervasives.Lemma
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash =
false
null
true
let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.word", "Hacl.Spec.SHA2.Vec.words_state'", "Hacl.Spec.SHA2.Equiv.seq_of_list_is_create8", "Lib.IntTypes.int_t", "Spec.Hash.Definitions.word_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Dot", "Hacl.Spec.SHA2._Sigma0", "Hacl.Spec.SHA2._Maj", "Hacl.Spec.SHA2._Sigma1", "Hacl.Spec.SHA2._Ch", "FStar.Seq.Base.index", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
[]
Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8_lemma
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Hash.Definitions.sha2_alg -> k_t: Hacl.Spec.SHA2.Vec.word a -> ws_t: Hacl.Spec.SHA2.Vec.word a -> hash: Hacl.Spec.SHA2.Vec.words_state' a -> FStar.Pervasives.Lemma (ensures Hacl.Spec.SHA2.shuffle_core_pre a k_t ws_t hash == Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8 a k_t ws_t hash)
{ "end_col": 64, "end_line": 109, "start_col": 52, "start_line": 97 }
FStar.Pervasives.Lemma
val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_nblocks_lemma_l #a #m len b st l = let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks
val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) let update_nblocks_lemma_l #a #m len b st l =
false
null
true
let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Vec.state_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma", "Prims.int", "Prims.op_Division", "Spec.Hash.Definitions.block_length", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l val update_nblocks_loop_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= len / block_length a } -> Lemma ((state_spec_v (repeati n (update_block #a #m len b) st)).[l] == repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) let rec update_nblocks_loop_lemma #a #m len b st l n = let lp = repeati n (update_block #a #m len b) st in let f_sc = Spec.update_block a len b.(|l|) in let rp = repeati n f_sc (state_spec_v st).[l] in if n = 0 then begin eq_repeati0 n (update_block #a #m len b) st; eq_repeati0 n f_sc (state_spec_v st).[l] end else begin let lp1 = repeati (n - 1) (update_block #a #m len b) st in let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in update_nblocks_loop_lemma #a #m len b st l (n - 1); assert ((state_spec_v lp1).[l] == rp1); unfold_repeati n (update_block #a #m len b) st (n - 1); unfold_repeati n f_sc (state_spec_v st).[l] (n - 1); update_block_lemma_l #a #m len b (n - 1) lp1 l end val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
[]
Hacl.Spec.SHA2.Equiv.update_nblocks_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_nblocks len b st)).[ l ] == Hacl.Spec.SHA2.update_nblocks a len (( .(||) ) b l) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ] )
{ "end_col": 51, "end_line": 654, "start_col": 45, "start_line": 652 }
FStar.Pervasives.Lemma
val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_lemma #a #m len b = Classical.forall_intro (hash_lemma_l #a #m len b)
val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma #a #m len b =
false
null
true
Classical.forall_intro (hash_lemma_l #a #m len b)
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.IntTypes.uint8", "Prims.l_or", "FStar.Seq.Base.length", "Spec.Hash.Definitions.hash_length", "Lib.NTuple.op_Lens_Access", "FStar.Seq.Properties.lseq", "Hacl.Spec.SHA2.Vec.hash", "Hacl.Spec.SHA2.hash", "Hacl.Spec.SHA2.Equiv.hash_lemma_l", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l val update_nblocks_loop_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= len / block_length a } -> Lemma ((state_spec_v (repeati n (update_block #a #m len b) st)).[l] == repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) let rec update_nblocks_loop_lemma #a #m len b st l n = let lp = repeati n (update_block #a #m len b) st in let f_sc = Spec.update_block a len b.(|l|) in let rp = repeati n f_sc (state_spec_v st).[l] in if n = 0 then begin eq_repeati0 n (update_block #a #m len b) st; eq_repeati0 n f_sc (state_spec_v st).[l] end else begin let lp1 = repeati (n - 1) (update_block #a #m len b) st in let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in update_nblocks_loop_lemma #a #m len b st l (n - 1); assert ((state_spec_v lp1).[l] == rp1); unfold_repeati n (update_block #a #m len b) st (n - 1); unfold_repeati n f_sc (state_spec_v st).[l] (n - 1); update_block_lemma_l #a #m len b (n - 1) lp1 l end val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) let update_nblocks_lemma_l #a #m len b st l = let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma_l #a #m len b l = let len' : len_t a = Spec.mk_len_t a len in let st0 = init a m in init_lemma_l a m l; let st1 = update_nblocks #a #m len b st0 in update_nblocks_lemma_l #a #m len b st0 l; let rem = len % block_length a in let mb = get_multilast_spec #a #m len b in let st = update_last len' rem mb st1 in update_last_lemma_l len' rem mb st1 l; finish_lemma_l st l val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
[]
Hacl.Spec.SHA2.Equiv.hash_lemma
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> FStar.Pervasives.Lemma (ensures forall (l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}). ( .(||) ) (Hacl.Spec.SHA2.Vec.hash len b) l == Hacl.Spec.SHA2.hash len (( .(||) ) b l))
{ "end_col": 51, "end_line": 687, "start_col": 2, "start_line": 687 }
FStar.Pervasives.Lemma
val hash_agile_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_agile_lemma #a #m len b = Classical.forall_intro (hash_agile_lemma_l #a #m len b)
val hash_agile_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) let hash_agile_lemma #a #m len b =
false
null
true
Classical.forall_intro (hash_agile_lemma_l #a #m len b)
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.IntTypes.uint8", "Prims.l_or", "FStar.Seq.Base.length", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Hash.Definitions.hash_length'", "Lib.NTuple.op_Lens_Access", "FStar.Seq.Properties.lseq", "Hacl.Spec.SHA2.Vec.hash", "Spec.Agile.Hash.hash", "Hacl.Spec.SHA2.Equiv.hash_agile_lemma_l", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l val update_nblocks_loop_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= len / block_length a } -> Lemma ((state_spec_v (repeati n (update_block #a #m len b) st)).[l] == repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) let rec update_nblocks_loop_lemma #a #m len b st l n = let lp = repeati n (update_block #a #m len b) st in let f_sc = Spec.update_block a len b.(|l|) in let rp = repeati n f_sc (state_spec_v st).[l] in if n = 0 then begin eq_repeati0 n (update_block #a #m len b) st; eq_repeati0 n f_sc (state_spec_v st).[l] end else begin let lp1 = repeati (n - 1) (update_block #a #m len b) st in let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in update_nblocks_loop_lemma #a #m len b st l (n - 1); assert ((state_spec_v lp1).[l] == rp1); unfold_repeati n (update_block #a #m len b) st (n - 1); unfold_repeati n f_sc (state_spec_v st).[l] (n - 1); update_block_lemma_l #a #m len b (n - 1) lp1 l end val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) let update_nblocks_lemma_l #a #m len b st l = let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma_l #a #m len b l = let len' : len_t a = Spec.mk_len_t a len in let st0 = init a m in init_lemma_l a m l; let st1 = update_nblocks #a #m len b st0 in update_nblocks_lemma_l #a #m len b st0 l; let rem = len % block_length a in let mb = get_multilast_spec #a #m len b in let st = update_last len' rem mb st1 in update_last_lemma_l len' rem mb st1 l; finish_lemma_l st l val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma #a #m len b = Classical.forall_intro (hash_lemma_l #a #m len b) val hash_agile_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) let hash_agile_lemma_l #a #m len b l = hash_lemma_l #a #m len b l; Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(|l|) val hash_agile_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_agile_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
[]
Hacl.Spec.SHA2.Equiv.hash_agile_lemma
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> FStar.Pervasives.Lemma (ensures forall (l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}). ( .(||) ) (Hacl.Spec.SHA2.Vec.hash len b) l == Spec.Agile.Hash.hash a (( .(||) ) b l))
{ "end_col": 57, "end_line": 712, "start_col": 2, "start_line": 712 }
FStar.Pervasives.Lemma
val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l
val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l =
false
null
true
let mb = get_multiblock_spec len b i in update_lemma_l mb st l
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Spec.Hash.Definitions.block_length", "Hacl.Spec.SHA2.Vec.state_spec", "Hacl.Spec.SHA2.Equiv.update_lemma_l", "Hacl.Spec.SHA2.Vec.get_multiblock_spec", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
[]
Hacl.Spec.SHA2.Equiv.update_block_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> i: Prims.nat{i < len / Spec.Hash.Definitions.block_length a} -> st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_block len b i st)).[ l ] == Hacl.Spec.SHA2.update_block a len (( .(||) ) b l) i (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ] )
{ "end_col": 24, "end_line": 608, "start_col": 45, "start_line": 606 }
FStar.Pervasives.Lemma
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l =
false
null
true
eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[ l ] (Spec.init a)
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Vec.lanes", "Lib.Sequence.eq_intro", "Hacl.Spec.SHA2.Vec.word", "Spec.Hash.Definitions.state_word_length", "Lib.Sequence.op_String_Access", "Hacl.Spec.SHA2.Vec.words_state'", "Hacl.Spec.SHA2.Vec.state_spec_v", "Hacl.Spec.SHA2.Vec.init", "Hacl.Spec.SHA2.init", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
[]
Hacl.Spec.SHA2.Equiv.init_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.init a m)).[ l ] == Hacl.Spec.SHA2.init a )
{ "end_col": 47, "end_line": 300, "start_col": 2, "start_line": 299 }
FStar.Pervasives.Lemma
val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l
val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l =
false
null
true
let blocks = padded_blocks a len in let fin:nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let b0, b1 = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Spec.Hash.Definitions.len_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.Hash.Definitions.block_length", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Vec.state_spec", "Prims.op_LessThan", "Hacl.Spec.SHA2.Equiv.update_lemma_l", "Prims.unit", "Hacl.Spec.SHA2.Vec.update", "Hacl.Spec.SHA2.Equiv.load_last_lemma_l", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.SHA2.Vec.load_last", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.numbytes", "Spec.Hash.Definitions.len_int_type", "Lib.ByteSequence.uint_to_bytes_be", "Prims.eq2", "Prims.int", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Lib.IntTypes.shift_left", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.IntTypes.secret", "FStar.UInt32.__uint_to_t", "FStar.Mul.op_Star", "Hacl.Spec.SHA2.Vec.padded_blocks" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
[]
Hacl.Spec.SHA2.Equiv.update_last_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
totlen: Spec.Hash.Definitions.len_t a -> len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_last totlen len b st)).[ l ] == Hacl.Spec.SHA2.update_last a totlen len (( .(||) ) b l) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ])
{ "end_col": 24, "end_line": 494, "start_col": 50, "start_line": 485 }
FStar.Pervasives.Lemma
val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l =
false
null
true
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.ws_spec", "Hacl.Spec.SHA2.Vec.state_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma", "Hacl.Spec.SHA2.num_rounds16", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
[]
Hacl.Spec.SHA2.Equiv.shuffle_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle ws st)).[ l ] == Hacl.Spec.SHA2.shuffle a (Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ] (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ])
{ "end_col": 56, "end_line": 293, "start_col": 2, "start_line": 293 }
FStar.Pervasives.Lemma
val hash_agile_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_agile_lemma_l #a #m len b l = hash_lemma_l #a #m len b l; Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(|l|)
val hash_agile_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) let hash_agile_lemma_l #a #m len b l =
false
null
true
hash_lemma_l #a #m len b l; Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(| l |)
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma", "Lib.NTuple.op_Lens_Access", "FStar.Seq.Properties.lseq", "Lib.IntTypes.uint8", "Prims.unit", "Hacl.Spec.SHA2.Equiv.hash_lemma_l" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l val update_nblocks_loop_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= len / block_length a } -> Lemma ((state_spec_v (repeati n (update_block #a #m len b) st)).[l] == repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) let rec update_nblocks_loop_lemma #a #m len b st l n = let lp = repeati n (update_block #a #m len b) st in let f_sc = Spec.update_block a len b.(|l|) in let rp = repeati n f_sc (state_spec_v st).[l] in if n = 0 then begin eq_repeati0 n (update_block #a #m len b) st; eq_repeati0 n f_sc (state_spec_v st).[l] end else begin let lp1 = repeati (n - 1) (update_block #a #m len b) st in let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in update_nblocks_loop_lemma #a #m len b st l (n - 1); assert ((state_spec_v lp1).[l] == rp1); unfold_repeati n (update_block #a #m len b) st (n - 1); unfold_repeati n f_sc (state_spec_v st).[l] (n - 1); update_block_lemma_l #a #m len b (n - 1) lp1 l end val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) let update_nblocks_lemma_l #a #m len b st l = let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma_l #a #m len b l = let len' : len_t a = Spec.mk_len_t a len in let st0 = init a m in init_lemma_l a m l; let st1 = update_nblocks #a #m len b st0 in update_nblocks_lemma_l #a #m len b st0 l; let rem = len % block_length a in let mb = get_multilast_spec #a #m len b in let st = update_last len' rem mb st1 in update_last_lemma_l len' rem mb st1 l; finish_lemma_l st l val hash_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> Lemma (forall (l:nat{l < lanes a m}). (hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma #a #m len b = Classical.forall_intro (hash_lemma_l #a #m len b) val hash_agile_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_agile_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
[]
Hacl.Spec.SHA2.Equiv.hash_agile_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures ( .(||) ) (Hacl.Spec.SHA2.Vec.hash len b) l == Spec.Agile.Hash.hash a (( .(||) ) b l))
{ "end_col": 60, "end_line": 700, "start_col": 2, "start_line": 699 }
FStar.Pervasives.Lemma
val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_lemma_l #a #m len b l = let len' : len_t a = Spec.mk_len_t a len in let st0 = init a m in init_lemma_l a m l; let st1 = update_nblocks #a #m len b st0 in update_nblocks_lemma_l #a #m len b st0 l; let rem = len % block_length a in let mb = get_multilast_spec #a #m len b in let st = update_last len' rem mb st1 in update_last_lemma_l len' rem mb st1 l; finish_lemma_l st l
val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) let hash_lemma_l #a #m len b l =
false
null
true
let len':len_t a = Spec.mk_len_t a len in let st0 = init a m in init_lemma_l a m l; let st1 = update_nblocks #a #m len b st0 in update_nblocks_lemma_l #a #m len b st0 l; let rem = len % block_length a in let mb = get_multilast_spec #a #m len b in let st = update_last len' rem mb st1 in update_last_lemma_l len' rem mb st1 l; finish_lemma_l st l
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.len_lt_max_a_t", "Hacl.Spec.SHA2.Vec.multiseq", "Hacl.Spec.SHA2.Vec.lanes", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Equiv.finish_lemma_l", "Prims.unit", "Hacl.Spec.SHA2.Equiv.update_last_lemma_l", "Hacl.Spec.SHA2.Vec.state_spec", "Hacl.Spec.SHA2.Vec.update_last", "Prims.op_Modulus", "Spec.Hash.Definitions.block_length", "Hacl.Spec.SHA2.Vec.get_multilast_spec", "Prims.int", "Hacl.Spec.SHA2.Equiv.update_nblocks_lemma_l", "Hacl.Spec.SHA2.Vec.update_nblocks", "Hacl.Spec.SHA2.Equiv.init_lemma_l", "Hacl.Spec.SHA2.Vec.init", "Spec.Hash.Definitions.len_t", "Hacl.Spec.SHA2.mk_len_t" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l val update_block_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> i:nat{i < len / block_length a} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_block len b i st)).[l] == Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) let update_block_lemma_l #a #m len b i st l = let mb = get_multiblock_spec len b i in update_lemma_l mb st l val update_nblocks_loop_lemma: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= len / block_length a } -> Lemma ((state_spec_v (repeati n (update_block #a #m len b) st)).[l] == repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) let rec update_nblocks_loop_lemma #a #m len b st l n = let lp = repeati n (update_block #a #m len b) st in let f_sc = Spec.update_block a len b.(|l|) in let rp = repeati n f_sc (state_spec_v st).[l] in if n = 0 then begin eq_repeati0 n (update_block #a #m len b) st; eq_repeati0 n f_sc (state_spec_v st).[l] end else begin let lp1 = repeati (n - 1) (update_block #a #m len b) st in let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in update_nblocks_loop_lemma #a #m len b st l (n - 1); assert ((state_spec_v lp1).[l] == rp1); unfold_repeati n (update_block #a #m len b) st (n - 1); unfold_repeati n f_sc (state_spec_v st).[l] (n - 1); update_block_lemma_l #a #m len b (n - 1) lp1 l end val update_nblocks_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_nblocks len b st)).[l] == Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) let update_nblocks_lemma_l #a #m len b st l = let blocks = len / block_length a in update_nblocks_loop_lemma #a #m len b st l blocks val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> len:Spec.len_lt_max_a_t a -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
[]
Hacl.Spec.SHA2.Equiv.hash_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Hacl.Spec.SHA2.len_lt_max_a_t a -> b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures ( .(||) ) (Hacl.Spec.SHA2.Vec.hash len b) l == Hacl.Spec.SHA2.hash len (( .(||) ) b l))
{ "end_col": 21, "end_line": 675, "start_col": 32, "start_line": 665 }
FStar.Pervasives.Lemma
val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finish_lemma_l #a #m st l = store_state_lemma_l #a #m st l
val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) let finish_lemma_l #a #m st l =
false
null
true
store_state_lemma_l #a #m st l
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.Vec.state_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Equiv.store_state_lemma_l", "Prims.unit" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp #pop-options val state_spec_v_map2_add: #a:sha2_alg -> #m:m_spec -> st1:state_spec a m -> st2:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] == map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) let state_spec_v_map2_add #a #m st1 st2 l = eq_intro (state_spec_v (map2 (+|) st1 st2)).[l] (map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) val update_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update b st)).[l] == Spec.update a b.(|l|) (state_spec_v st).[l]) let update_lemma_l #a #m b st l = reveal_opaque (`%update) (update #a #m); let ws = load_ws b in load_ws_lemma_l b l; let st1 = shuffle ws st in shuffle_lemma_l ws st l; let res = map2 (+|) st1 st in state_spec_v_map2_add #a #m st1 st l val load_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen_seq:lseq uint8 (len_length a) -> fin:nat{fin == block_length a \/ fin == 2 * block_length a} -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> l:nat{l < lanes a m} -> Lemma (let (b0_v, b1_v) = load_last totlen_seq fin len b in let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) let load_last_lemma_l #a #m totlen_seq fin len b l = reveal_opaque (`%load_last) (load_last #a #m); allow_inversion sha2_alg; allow_inversion m_spec val update_last_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> totlen:len_t a -> len:nat{len <= block_length a} -> b:multiseq (lanes a m) len -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (update_last totlen len b st)).[l] == Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) let update_last_lemma_l #a #m totlen len b st0 l = let blocks = padded_blocks a len in let fin : nat = blocks * block_length a in let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in let (b0,b1) = load_last #a #m totlen_seq fin len b in load_last_lemma_l #a #m totlen_seq fin len b l; let st = update b0 st0 in update_lemma_l b0 st0 l; update_lemma_l b1 st l val store_state_lemma_ij: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 8 * word_length a} -> Lemma ((store_state st).[j * (8 * word_length a) + i] == (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) let store_state_lemma_ij #a #m st j i = let st1 = transpose_state st in let j_v = j * (8 * word_length a) + i in let blocksize_v = word_length a * lanes a m in calc (==) { // j_v % blocksize_v / word_length a (j * (8 * word_length a) + i) % blocksize_v / word_length a; (==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a % lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) % lanes a m; }; calc (==) { // j_v / blocksize_v (j * (8 * word_length a) + i) / (word_length a * lanes a m); (==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) } (j * (8 * word_length a) + i) / word_length a / lanes a m; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) } (8 * j + i / word_length a) / lanes a m; }; calc (==) { Seq.index (store_state st) j_v; (==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v } (BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v]; (==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a]; (==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) } (BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a]; (==) { Lemmas.transpose_state_lemma_ij #a #m st j i } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a]; (==) { Math.Lemmas.paren_mul_right j 8 (word_length a); Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) } (BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]; } val store_state_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) == Spec.store_state a (state_spec_v st).[l]) let store_state_lemma_l #a #m st l = let st_l : words_state a = (state_spec_v st).[l] in let rp = Spec.store_state a st_l in let lp = store_state st in let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) = //assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l); BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i; store_state_lemma_ij #a #m st l i in Classical.forall_intro aux; eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a)) (Spec.store_state a (state_spec_v st).[l]) // val emit_lemma_l: // #a:sha2_alg // -> #m:m_spec // -> hseq:lseq uint8 (lanes a m * 8 * word_length a) // -> l:nat{l < lanes a m} -> // Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a))) // let emit_lemma_l #a #m hseq l = () val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finish_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
[]
Hacl.Spec.SHA2.Equiv.finish_lemma_l
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures ( .(||) ) (Hacl.Spec.SHA2.Vec.finish st) l == Hacl.Spec.SHA2.finish a (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ])
{ "end_col": 32, "end_line": 591, "start_col": 2, "start_line": 591 }
FStar.Pervasives.Lemma
val _Maj_lemma (#a #m x y z: _) : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Maj x y z)]
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
val _Maj_lemma (#a #m x y z: _) : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Maj x y z)] let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Maj x y z)] =
false
null
true
LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Lib.IntVector.vec_t", "Spec.Hash.Definitions.word_t", "Hacl.Spec.SHA2.Vec.lanes", "Lib.Sequence.eq_intro", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Lib.IntVector.vec_v", "Hacl.Spec.SHA2.Vec._Maj", "Lib.Sequence.createi", "Spec.Hash.Definitions.word", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2._Maj", "Lib.Sequence.op_String_Access", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.l_and", "FStar.Seq.Base.length", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Hacl.Spec.SHA2.Vec.element_t", "Prims.Nil" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)]
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _Maj_lemma (#a #m x y z: _) : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Maj x y z)]
[]
Hacl.Spec.SHA2.Equiv._Maj_lemma
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> y: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> z: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> FStar.Pervasives.Lemma (ensures Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Maj x y z) == Lib.Sequence.createi (Hacl.Spec.SHA2.Vec.lanes a m) (fun i -> Hacl.Spec.SHA2._Maj a (Lib.IntVector.vec_v x).[ i ] (Lib.IntVector.vec_v y).[ i ] (Lib.IntVector.vec_v z).[ i ])) [SMTPat (Hacl.Spec.SHA2.Vec._Maj x y z)]
{ "end_col": 95, "end_line": 36, "start_col": 2, "start_line": 35 }
FStar.Pervasives.Lemma
val _Ch_lemma (#a #m x y z: _) : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Ch x y z)]
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
val _Ch_lemma (#a #m x y z: _) : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Ch x y z)] let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Ch x y z)] =
false
null
true
LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
{ "checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.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": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ "lemma" ]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Lib.IntVector.vec_t", "Spec.Hash.Definitions.word_t", "Hacl.Spec.SHA2.Vec.lanes", "Lib.Sequence.eq_intro", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Lib.IntVector.vec_v", "Hacl.Spec.SHA2.Vec._Ch", "Lib.Sequence.createi", "Spec.Hash.Definitions.word", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2._Ch", "Lib.Sequence.op_String_Access", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Lib.Sequence.seq", "Prims.l_or", "Prims.l_and", "FStar.Seq.Base.length", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Hacl.Spec.SHA2.Vec.element_t", "Prims.Nil" ]
[]
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)]
false
false
Hacl.Spec.SHA2.Equiv.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val _Ch_lemma (#a #m x y z: _) : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) [SMTPat (_Ch x y z)]
[]
Hacl.Spec.SHA2.Equiv._Ch_lemma
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> y: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> z: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) -> FStar.Pervasives.Lemma (ensures Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Ch x y z) == Lib.Sequence.createi (Hacl.Spec.SHA2.Vec.lanes a m) (fun i -> Hacl.Spec.SHA2._Ch a (Lib.IntVector.vec_v x).[ i ] (Lib.IntVector.vec_v y).[ i ] (Lib.IntVector.vec_v z).[ i ])) [SMTPat (Hacl.Spec.SHA2.Vec._Ch x y z)]
{ "end_col": 94, "end_line": 27, "start_col": 2, "start_line": 26 }