file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Vale.AsLowStar.MemoryHelpers.fst
Vale.AsLowStar.MemoryHelpers.bounded_buffer_addrs_one
val bounded_buffer_addrs_one (src t:base_typ) (h:HS.mem) (b:buf_t src t{B.live h b}) (s:ME.vale_heap) : Lemma (ME.buffer_addr #t (as_vale_buffer b) s + DV.length (get_downview b) < Vale.Def.Words_s.pow2_64)
val bounded_buffer_addrs_one (src t:base_typ) (h:HS.mem) (b:buf_t src t{B.live h b}) (s:ME.vale_heap) : Lemma (ME.buffer_addr #t (as_vale_buffer b) s + DV.length (get_downview b) < Vale.Def.Words_s.pow2_64)
let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 105, "end_line": 117, "start_col": 0, "start_line": 117 }
module Vale.AsLowStar.MemoryHelpers open FStar.Mul open Vale.Arch.HeapImpl open Vale.X64.MemoryAdapters open Vale.Interop.Base module B = LowStar.Buffer module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down module ME = Vale.X64.Memory module VSig = Vale.AsLowStar.ValeSig module IX64 = Vale.Interop.X64 friend Vale.X64.Memory friend Vale.X64.Memory_Sems friend Vale.X64.Stack_i friend Vale.X64.Stack_Sems friend Vale.X64.Decls friend Vale.X64.StateLemmas friend Vale.X64.MemoryAdapters let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () let rec loc_eq (args:list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) = match args with | [] -> () | hd :: tl -> loc_eq tl let relate_modifies args m0 m1 = loc_eq args let reveal_readable #src #t x s = () let reveal_imm_readable #src #t x s = () let readable_live #src #t x s = () let readable_imm_live #src #t x s = () let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap //let get_heap_mk_mem_reveal args h0 = () let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let mk_stack_reveal stack = () let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let buffer_as_seq_reveal2 src t x va_s = () let immbuffer_as_seq_reveal2 src t x va_s = () let buffer_addr_reveal src t x args h0 = () let immbuffer_addr_reveal src t x args h0 = () let fuel_eq = () let decls_eval_code_reveal c va_s0 va_s1 f = () let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let modifies_same_roots s h0 h1 = () let modifies_equal_domains s h0 h1 = () let loc_disjoint_sym x y = () #set-options "--z3rlimit 20" let core_create_lemma_taint_hyp #max_arity #arg_reg (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in // assert (mem == mk_mem args h0); let raw_taint = IX64.(mk_taint args IX64.init_taint) in // assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint); ME.valid_memtaint mem (args_b8 args) raw_taint; // assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args let buffer_writeable_reveal src t x = () let buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let imm_buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let buffer_as_seq_invert src t h s b = let db = get_downview b in DV.length_eq db; assert (Seq.equal (ME.buffer_as_seq s (as_vale_buffer b)) (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t))))) let buffer_as_seq_reveal_tuint128 src x va_s = () let immbuffer_as_seq_reveal_tuint128 src x va_s = ()
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fst.checked", "Vale.X64.Stack_Sems.fst.checked", "Vale.X64.Stack_i.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.Memory_Sems.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Decls.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": true, "source_file": "Vale.AsLowStar.MemoryHelpers.fst" }
[ { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Vale.X64.Lemmas", "short_module": "VL" }, { "abbrev": true, "full_module": "Vale.X64.StateLemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_Sems", "short_module": "VSS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_i", "short_module": "SI" }, { "abbrev": true, "full_module": "Vale.X64.Memory_Sems", "short_module": "MES" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> h: FStar.Monotonic.HyperStack.mem -> b: Vale.Interop.Base.buf_t src t {LowStar.Monotonic.Buffer.live h b} -> s: Vale.X64.Memory.vale_heap -> FStar.Pervasives.Lemma (ensures Vale.X64.Memory.buffer_addr (Vale.X64.MemoryAdapters.as_vale_buffer b) s + LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) < Vale.Def.Words_s.pow2_64)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "FStar.Monotonic.HyperStack.mem", "Vale.Interop.Base.buf_t", "LowStar.Monotonic.Buffer.live", "Vale.Interop.Types.base_typ_as_type", "LowStar.Buffer.trivial_preorder", "Vale.X64.Memory.vale_heap", "FStar.Pervasives.reveal_opaque", "Vale.Interop.Types.b8", "Vale.Def.Words_s.nat64", "Prims.logical", "Vale.Interop.Types.addr_map_pred", "Prims.unit" ]
[]
true
false
true
false
false
let bounded_buffer_addrs_one src t h b s =
FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
false
Vale.AsLowStar.MemoryHelpers.fst
Vale.AsLowStar.MemoryHelpers.same_immbuffer_same_upviews
val same_immbuffer_same_upviews (#src #bt:base_typ) (b:ibuf_t src bt) (h0 h1:HS.mem) : Lemma (requires Seq.equal (B.as_seq h0 b) (B.as_seq h1 b)) (ensures ( let db = get_downview b in DV.length_eq db; let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in Seq.equal (UV.as_seq h0 ub) (UV.as_seq h1 ub)))
val same_immbuffer_same_upviews (#src #bt:base_typ) (b:ibuf_t src bt) (h0 h1:HS.mem) : Lemma (requires Seq.equal (B.as_seq h0 b) (B.as_seq h1 b)) (ensures ( let db = get_downview b in DV.length_eq db; let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in Seq.equal (UV.as_seq h0 ub) (UV.as_seq h1 ub)))
let same_immbuffer_same_upviews #src #bt b h0 h1 = let dv = get_downview b in let s0 = DV.as_seq h0 dv in let s1 = DV.as_seq h1 dv in let aux (i:nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) = DV.as_seq_sel h0 dv i; DV.as_seq_sel h1 dv i; DV.get_sel h0 dv i; DV.get_sel h1 dv i in Classical.forall_intro aux; Seq.lemma_eq_intro s0 s1; DV.length_eq dv; Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 172, "start_col": 0, "start_line": 160 }
module Vale.AsLowStar.MemoryHelpers open FStar.Mul open Vale.Arch.HeapImpl open Vale.X64.MemoryAdapters open Vale.Interop.Base module B = LowStar.Buffer module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down module ME = Vale.X64.Memory module VSig = Vale.AsLowStar.ValeSig module IX64 = Vale.Interop.X64 friend Vale.X64.Memory friend Vale.X64.Memory_Sems friend Vale.X64.Stack_i friend Vale.X64.Stack_Sems friend Vale.X64.Decls friend Vale.X64.StateLemmas friend Vale.X64.MemoryAdapters let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () let rec loc_eq (args:list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) = match args with | [] -> () | hd :: tl -> loc_eq tl let relate_modifies args m0 m1 = loc_eq args let reveal_readable #src #t x s = () let reveal_imm_readable #src #t x s = () let readable_live #src #t x s = () let readable_imm_live #src #t x s = () let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap //let get_heap_mk_mem_reveal args h0 = () let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let mk_stack_reveal stack = () let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let buffer_as_seq_reveal2 src t x va_s = () let immbuffer_as_seq_reveal2 src t x va_s = () let buffer_addr_reveal src t x args h0 = () let immbuffer_addr_reveal src t x args h0 = () let fuel_eq = () let decls_eval_code_reveal c va_s0 va_s1 f = () let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let modifies_same_roots s h0 h1 = () let modifies_equal_domains s h0 h1 = () let loc_disjoint_sym x y = () #set-options "--z3rlimit 20" let core_create_lemma_taint_hyp #max_arity #arg_reg (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in // assert (mem == mk_mem args h0); let raw_taint = IX64.(mk_taint args IX64.init_taint) in // assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint); ME.valid_memtaint mem (args_b8 args) raw_taint; // assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args let buffer_writeable_reveal src t x = () let buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let imm_buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let buffer_as_seq_invert src t h s b = let db = get_downview b in DV.length_eq db; assert (Seq.equal (ME.buffer_as_seq s (as_vale_buffer b)) (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t))))) let buffer_as_seq_reveal_tuint128 src x va_s = () let immbuffer_as_seq_reveal_tuint128 src x va_s = () let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred let same_down_up_buffer_length src b = let db = get_downview b in DV.length_eq db; FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src) #push-options "--z3rlimit 80" let down_up_buffer_read_reveal src h s b i = let db = get_downview b in let n:pos = view_n src in let up_view = (LSig.view_of_base_typ src) in let ub = UV.mk_buffer db up_view in same_down_up_buffer_length src b; UV.length_eq ub; UV.get_sel h ub i; FStar.Math.Lemmas.lemma_mult_lt_right n i (DV.length db / n); FStar.Math.Lemmas.multiply_fractions (DV.length db) n; FStar.Math.Lemmas.nat_times_nat_is_nat i n; assert (low_buffer_read src src h b i == UV.View?.get up_view (Seq.slice (DV.as_seq h db) (i*n) (i*n + n))); DV.put_sel h db (i*n); let aux () : Lemma (n * ((i*n)/n) == i*n) = FStar.Math.Lemmas.cancel_mul_div i n in aux() #pop-options let same_buffer_same_upviews #src #bt b h0 h1 = let dv = get_downview b in let s0 = DV.as_seq h0 dv in let s1 = DV.as_seq h1 dv in let aux (i:nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) = DV.as_seq_sel h0 dv i; DV.as_seq_sel h1 dv i; DV.get_sel h0 dv i; DV.get_sel h1 dv i in Classical.forall_intro aux; Seq.lemma_eq_intro s0 s1; DV.length_eq dv; Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fst.checked", "Vale.X64.Stack_Sems.fst.checked", "Vale.X64.Stack_i.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.Memory_Sems.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Decls.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": true, "source_file": "Vale.AsLowStar.MemoryHelpers.fst" }
[ { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Vale.X64.Lemmas", "short_module": "VL" }, { "abbrev": true, "full_module": "Vale.X64.StateLemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_Sems", "short_module": "VSS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_i", "short_module": "SI" }, { "abbrev": true, "full_module": "Vale.X64.Memory_Sems", "short_module": "MES" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.Interop.Base.ibuf_t src bt -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal (LowStar.Monotonic.Buffer.as_seq h0 b) (LowStar.Monotonic.Buffer.as_seq h1 b)) (ensures (let db = Vale.Interop.Types.get_downview b in LowStar.BufferView.Down.length_eq db; let ub = LowStar.BufferView.Up.mk_buffer db (Vale.AsLowStar.LowStarSig.view_of_base_typ bt) in FStar.Seq.Base.equal (LowStar.BufferView.Up.as_seq h0 ub) (LowStar.BufferView.Up.as_seq h1 ub)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Vale.Interop.Base.ibuf_t", "FStar.Monotonic.HyperStack.mem", "Vale.Lib.BufferViewHelpers.lemma_uv_equal", "FStar.UInt8.t", "Vale.Interop.Types.base_typ_as_type", "Vale.AsLowStar.LowStarSig.view_of_base_typ", "Prims.unit", "LowStar.BufferView.Down.length_eq", "FStar.Seq.Base.lemma_eq_intro", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowStar.BufferView.Down.length", "Prims.eq2", "FStar.Seq.Base.index", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowStar.BufferView.Down.get_sel", "LowStar.BufferView.Down.as_seq_sel", "FStar.Seq.Properties.lseq", "LowStar.BufferView.Down.as_seq", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview", "LowStar.ImmutableBuffer.immutable_preorder" ]
[]
false
false
true
false
false
let same_immbuffer_same_upviews #src #bt b h0 h1 =
let dv = get_downview b in let s0 = DV.as_seq h0 dv in let s1 = DV.as_seq h1 dv in let aux (i: nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) = DV.as_seq_sel h0 dv i; DV.as_seq_sel h1 dv i; DV.get_sel h0 dv i; DV.get_sel h1 dv i in Classical.forall_intro aux; Seq.lemma_eq_intro s0 s1; DV.length_eq dv; Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1
false
Vale.AsLowStar.MemoryHelpers.fst
Vale.AsLowStar.MemoryHelpers.core_create_lemma_taint_hyp
val core_create_lemma_taint_hyp (#max_arity:nat) (#arg_reg:IX64.arg_reg_relation max_arity) (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s))
val core_create_lemma_taint_hyp (#max_arity:nat) (#arg_reg:IX64.arg_reg_relation max_arity) (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s))
let core_create_lemma_taint_hyp #max_arity #arg_reg (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in // assert (mem == mk_mem args h0); let raw_taint = IX64.(mk_taint args IX64.init_taint) in // assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint); ME.valid_memtaint mem (args_b8 args) raw_taint; // assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 90, "start_col": 0, "start_line": 65 }
module Vale.AsLowStar.MemoryHelpers open FStar.Mul open Vale.Arch.HeapImpl open Vale.X64.MemoryAdapters open Vale.Interop.Base module B = LowStar.Buffer module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down module ME = Vale.X64.Memory module VSig = Vale.AsLowStar.ValeSig module IX64 = Vale.Interop.X64 friend Vale.X64.Memory friend Vale.X64.Memory_Sems friend Vale.X64.Stack_i friend Vale.X64.Stack_Sems friend Vale.X64.Decls friend Vale.X64.StateLemmas friend Vale.X64.MemoryAdapters let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () let rec loc_eq (args:list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) = match args with | [] -> () | hd :: tl -> loc_eq tl let relate_modifies args m0 m1 = loc_eq args let reveal_readable #src #t x s = () let reveal_imm_readable #src #t x s = () let readable_live #src #t x s = () let readable_imm_live #src #t x s = () let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap //let get_heap_mk_mem_reveal args h0 = () let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let mk_stack_reveal stack = () let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let buffer_as_seq_reveal2 src t x va_s = () let immbuffer_as_seq_reveal2 src t x va_s = () let buffer_addr_reveal src t x args h0 = () let immbuffer_addr_reveal src t x args h0 = () let fuel_eq = () let decls_eval_code_reveal c va_s0 va_s1 f = () let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let modifies_same_roots s h0 h1 = () let modifies_equal_domains s h0 h1 = () let loc_disjoint_sym x y = () #set-options "--z3rlimit 20"
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fst.checked", "Vale.X64.Stack_Sems.fst.checked", "Vale.X64.Stack_i.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.Memory_Sems.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Decls.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": true, "source_file": "Vale.AsLowStar.MemoryHelpers.fst" }
[ { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Vale.X64.Lemmas", "short_module": "VL" }, { "abbrev": true, "full_module": "Vale.X64.StateLemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_Sems", "short_module": "VSS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_i", "short_module": "SI" }, { "abbrev": true, "full_module": "Vale.X64.Memory_Sems", "short_module": "MES" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
args: Vale.Interop.X64.arg_list -> h0: FStar.Monotonic.HyperStack.mem{Vale.Interop.Base.mem_roots_p h0 args} -> FStar.Pervasives.Lemma (ensures (let va_s = Vale.AsLowStar.LowStarSig.create_initial_vale_state args h0 in Vale.AsLowStar.LowStarSig.taint_hyp args va_s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Vale.Interop.X64.arg_reg_relation", "Vale.Interop.X64.arg_list", "FStar.Monotonic.HyperStack.mem", "Vale.Interop.Base.mem_roots_p", "FStar.BigOps.big_and'_forall", "Vale.Interop.Base.arg", "Vale.AsLowStar.LowStarSig.taint_hyp_arg", "Prims.unit", "Prims._assert", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "FStar.List.Tot.Base.memP", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Vale.Arch.HeapTypes_s.taint", "Vale.Interop.X64.taint_of_arg", "FStar.Classical.forall_intro", "Vale.Interop.Types.b8", "Prims.l_iff", "Vale.Interop.Base.args_b8", "Prims.l_Exists", "Vale.Interop.Base.valid_base_type", "Vale.Interop.Base.td_as_type", "Vale.Interop.Base.TD_Base", "Prims.l_False", "Vale.Arch.HeapTypes_s.base_typ", "Vale.Interop.Base.buffer_qualifiers", "Vale.Interop.Base.TD_Buffer", "Prims.eq2", "Vale.Interop.Base.mut_to_b8", "Vale.Interop.Base.TD_ImmBuffer", "Vale.Interop.Base.imm_to_b8", "Prims.logical", "Vale.Interop.Base.args_b8_mem", "FStar.Pervasives.Native.__proj__Some__item__v", "Vale.Interop.X64.taint_arg_b8", "Vale.Interop.X64.mk_taint", "Vale.Interop.X64.init_taint", "Vale.Interop.X64.mk_taint_equiv", "Vale.X64.Memory.valid_taint_b8", "Vale.X64.Memory.valid_memtaint", "Vale.Interop.X64.taint_map", "Vale.Arch.HeapImpl.vale_heap", "Vale.X64.Memory.get_vale_heap", "Vale.X64.State.__proj__Mkvale_state__item__vs_heap", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.Arch.HeapImpl.full_heap_taint", "Vale.X64.Decls.vale_state_with_inv", "Vale.AsLowStar.LowStarSig.create_initial_vale_state", "FStar.Pervasives.reveal_opaque", "Vale.X64.Memory.vale_full_heap", "Vale.X64.Memory.vale_heap", "Prims.l_True", "Prims.squash", "Vale.AsLowStar.LowStarSig.taint_hyp", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let core_create_lemma_taint_hyp #max_arity #arg_reg (args: IX64.arg_list) (h0: HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) =
FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in let raw_taint = let open IX64 in mk_taint args IX64.init_taint in ME.valid_memtaint mem (args_b8 args) raw_taint; assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a: arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
false
Vale.AsLowStar.MemoryHelpers.fst
Vale.AsLowStar.MemoryHelpers.buffer_as_seq_invert
val buffer_as_seq_invert (src t:base_typ) (h:HS.mem) (s:ME.vale_heap) (b:(buf_t src t){B.live h b}) : Lemma (requires ( DV.length_eq (get_downview b); Seq.equal (LSig.nat_to_uint_seq_t t (ME.buffer_as_seq s (as_vale_buffer b))) (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))))) (ensures ME.buffer_as_seq s (as_vale_buffer b) == (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))))) [SMTPat (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))); SMTPat (ME.buffer_as_seq s (as_vale_buffer b))]
val buffer_as_seq_invert (src t:base_typ) (h:HS.mem) (s:ME.vale_heap) (b:(buf_t src t){B.live h b}) : Lemma (requires ( DV.length_eq (get_downview b); Seq.equal (LSig.nat_to_uint_seq_t t (ME.buffer_as_seq s (as_vale_buffer b))) (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))))) (ensures ME.buffer_as_seq s (as_vale_buffer b) == (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))))) [SMTPat (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ t))); SMTPat (ME.buffer_as_seq s (as_vale_buffer b))]
let buffer_as_seq_invert src t h s b = let db = get_downview b in DV.length_eq db; assert (Seq.equal (ME.buffer_as_seq s (as_vale_buffer b)) (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 111, "start_col": 0, "start_line": 106 }
module Vale.AsLowStar.MemoryHelpers open FStar.Mul open Vale.Arch.HeapImpl open Vale.X64.MemoryAdapters open Vale.Interop.Base module B = LowStar.Buffer module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down module ME = Vale.X64.Memory module VSig = Vale.AsLowStar.ValeSig module IX64 = Vale.Interop.X64 friend Vale.X64.Memory friend Vale.X64.Memory_Sems friend Vale.X64.Stack_i friend Vale.X64.Stack_Sems friend Vale.X64.Decls friend Vale.X64.StateLemmas friend Vale.X64.MemoryAdapters let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () let rec loc_eq (args:list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) = match args with | [] -> () | hd :: tl -> loc_eq tl let relate_modifies args m0 m1 = loc_eq args let reveal_readable #src #t x s = () let reveal_imm_readable #src #t x s = () let readable_live #src #t x s = () let readable_imm_live #src #t x s = () let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap //let get_heap_mk_mem_reveal args h0 = () let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let mk_stack_reveal stack = () let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let buffer_as_seq_reveal2 src t x va_s = () let immbuffer_as_seq_reveal2 src t x va_s = () let buffer_addr_reveal src t x args h0 = () let immbuffer_addr_reveal src t x args h0 = () let fuel_eq = () let decls_eval_code_reveal c va_s0 va_s1 f = () let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let modifies_same_roots s h0 h1 = () let modifies_equal_domains s h0 h1 = () let loc_disjoint_sym x y = () #set-options "--z3rlimit 20" let core_create_lemma_taint_hyp #max_arity #arg_reg (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in // assert (mem == mk_mem args h0); let raw_taint = IX64.(mk_taint args IX64.init_taint) in // assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint); ME.valid_memtaint mem (args_b8 args) raw_taint; // assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args let buffer_writeable_reveal src t x = () let buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let imm_buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fst.checked", "Vale.X64.Stack_Sems.fst.checked", "Vale.X64.Stack_i.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.Memory_Sems.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Decls.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": true, "source_file": "Vale.AsLowStar.MemoryHelpers.fst" }
[ { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Vale.X64.Lemmas", "short_module": "VL" }, { "abbrev": true, "full_module": "Vale.X64.StateLemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_Sems", "short_module": "VSS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_i", "short_module": "SI" }, { "abbrev": true, "full_module": "Vale.X64.Memory_Sems", "short_module": "MES" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
src: Vale.Arch.HeapTypes_s.base_typ -> t: Vale.Arch.HeapTypes_s.base_typ -> h: FStar.Monotonic.HyperStack.mem -> s: Vale.X64.Memory.vale_heap -> b: Vale.Interop.Base.buf_t src t {LowStar.Monotonic.Buffer.live h b} -> FStar.Pervasives.Lemma (requires (LowStar.BufferView.Down.length_eq (Vale.Interop.Types.get_downview b); FStar.Seq.Base.equal (Vale.AsLowStar.LowStarSig.nat_to_uint_seq_t t (Vale.X64.Memory.buffer_as_seq s (Vale.X64.MemoryAdapters.as_vale_buffer b))) (LowStar.BufferView.Up.as_seq h (LowStar.BufferView.Up.mk_buffer (Vale.Interop.Types.get_downview b) (Vale.AsLowStar.LowStarSig.view_of_base_typ t))))) (ensures Vale.X64.Memory.buffer_as_seq s (Vale.X64.MemoryAdapters.as_vale_buffer b) == Vale.AsLowStar.LowStarSig.uint_to_nat_seq_t t (LowStar.BufferView.Up.as_seq h (LowStar.BufferView.Up.mk_buffer (Vale.Interop.Types.get_downview b) (Vale.AsLowStar.LowStarSig.view_of_base_typ t)))) [ SMTPat (LowStar.BufferView.Up.as_seq h (LowStar.BufferView.Up.mk_buffer (Vale.Interop.Types.get_downview b) (Vale.AsLowStar.LowStarSig.view_of_base_typ t))); SMTPat (Vale.X64.Memory.buffer_as_seq s (Vale.X64.MemoryAdapters.as_vale_buffer b)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "FStar.Monotonic.HyperStack.mem", "Vale.X64.Memory.vale_heap", "Vale.Interop.Base.buf_t", "LowStar.Monotonic.Buffer.live", "Vale.Interop.Types.base_typ_as_type", "LowStar.Buffer.trivial_preorder", "Prims._assert", "FStar.Seq.Base.equal", "Vale.X64.Memory.base_typ_as_vale_type", "Vale.X64.Memory.buffer_as_seq", "Vale.X64.MemoryAdapters.as_vale_buffer", "Vale.AsLowStar.LowStarSig.uint_to_nat_seq_t", "LowStar.BufferView.Up.as_seq", "LowStar.BufferView.Up.mk_buffer", "FStar.UInt8.t", "Vale.AsLowStar.LowStarSig.view_of_base_typ", "Prims.unit", "LowStar.BufferView.Down.length_eq", "LowStar.BufferView.Down.buffer", "Vale.Interop.Types.get_downview" ]
[]
true
false
true
false
false
let buffer_as_seq_invert src t h s b =
let db = get_downview b in DV.length_eq db; assert (Seq.equal (ME.buffer_as_seq s (as_vale_buffer b)) (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
false
Steel.ST.OnRange.fst
Steel.ST.OnRange.on_range_join
val on_range_join (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhostT unit opened (on_range p i j `star` on_range p j k) (fun _ -> on_range p i k)
val on_range_join (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhostT unit opened (on_range p i j `star` on_range p j k) (fun _ -> on_range p i k)
let rec on_range_join (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhostT unit opened (on_range p i j `star` on_range p j k) (fun _ -> on_range p i k) (decreases (if j >= i then j - i else 0)) = on_range_le p i j; on_range_le p j k; if i = j then begin rewrite (on_range p i j) emp; rewrite (on_range p j k) (on_range p i k) end else begin rewrite (on_range p i j) (p i `star` on_range p (i + 1) j); on_range_join p (i + 1) j k; rewrite (p i `star` on_range p (i + 1) k) (on_range p i k) end
{ "file_name": "lib/steel/Steel.ST.OnRange.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 76, "start_col": 0, "start_line": 58 }
module Steel.ST.OnRange open Steel.ST.GenElim let rec on_range (p: (nat -> vprop)) (i j: nat) : Tot vprop (decreases (if j <= i then 0 else j - i)) = if j < i then pure False else if j = i then emp else p i `star` on_range p (i + 1) j let on_range_le p i j = if i <= j then noop () else begin rewrite (on_range p i j) (pure False); let _ = gen_elim () in rewrite emp (on_range p i j); // by contradiction noop () end let on_range_empty p i j = rewrite emp (on_range p i j) let on_range_singleton_intro p i j = rewrite (p i `star` emp) (on_range p i j) let on_range_singleton_elim p i j = rewrite (on_range p i j) (p i `star` emp) let rec on_range_split (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhost unit opened (on_range p i k) (fun _ -> on_range p i j `star` on_range p j k) (i <= j /\ j <= k) (fun _ -> True) (decreases (j - i)) = if i = j then begin rewrite emp (on_range p i j); rewrite (on_range p i k) (on_range p j k) end else begin rewrite (on_range p i k) (p i `star` on_range p (i + 1) k); on_range_split p (i + 1) j k; rewrite (p i `star` on_range p (i + 1) j) (on_range p i j) end
{ "checked_file": "/", "dependencies": [ "Steel.ST.GenElim.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.OnRange.fst" }
[ { "abbrev": false, "full_module": "Steel.ST.GenElim", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat -> Steel.ST.Effect.Ghost.STGhostT Prims.unit
Steel.ST.Effect.Ghost.STGhostT
[ "" ]
[]
[ "Steel.Memory.inames", "Prims.nat", "Steel.Effect.Common.vprop", "Prims.op_Equality", "Steel.ST.Util.rewrite", "Steel.ST.OnRange.on_range", "Prims.unit", "Steel.Effect.Common.emp", "Prims.bool", "Steel.Effect.Common.star", "Prims.op_Addition", "Steel.ST.OnRange.on_range_join", "Steel.ST.OnRange.on_range_le" ]
[ "recursion" ]
false
true
false
false
false
let rec on_range_join (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhostT unit opened ((on_range p i j) `star` (on_range p j k)) (fun _ -> on_range p i k) (decreases (if j >= i then j - i else 0)) =
on_range_le p i j; on_range_le p j k; if i = j then (rewrite (on_range p i j) emp; rewrite (on_range p j k) (on_range p i k)) else (rewrite (on_range p i j) ((p i) `star` (on_range p (i + 1) j)); on_range_join p (i + 1) j k; rewrite ((p i) `star` (on_range p (i + 1) k)) (on_range p i k))
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.as_payload_list
val as_payload_list (h: HS.mem) (d: dll 'a) : GTot (list 'a)
val as_payload_list (h: HS.mem) (d: dll 'a) : GTot (list 'a)
let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 90, "start_col": 0, "start_line": 89 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.g_node_vals", "DoublyLinkedListIface.as_list", "Prims.list" ]
[]
false
false
false
false
false
let as_payload_list (h: HS.mem) (d: dll 'a) : GTot (list 'a) =
g_node_vals h (as_list h d)
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_at_head
val l_insert_at_head (l: list 'a) (x: 'a) : GTot (list 'a)
val l_insert_at_head (l: list 'a) (x: 'a) : GTot (list 'a)
let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 182, "start_col": 0, "start_line": 181 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.Cons" ]
[]
false
false
false
false
false
let l_insert_at_head (l: list 'a) (x: 'a) : GTot (list 'a) =
x :: l
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_at_tail
val l_insert_at_tail (l: list 'a) (x: 'a) : GTot (list 'a)
val l_insert_at_tail (l: list 'a) (x: 'a) : GTot (list 'a)
let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 185, "start_col": 0, "start_line": 184 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.snoc", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
false
false
false
let l_insert_at_tail (l: list 'a) (x: 'a) : GTot (list 'a) =
L.snoc (l, x)
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_remove_tail
val l_remove_tail (l: list 'a {L.length l > 0}) : GTot (list 'a)
val l_remove_tail (l: list 'a {L.length l > 0}) : GTot (list 'a)
let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l'
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 210, "start_col": 0, "start_line": 208 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a {FStar.List.Tot.Base.length l > 0} -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.b2t", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.unsnoc" ]
[]
false
false
false
false
false
let l_remove_tail (l: list 'a {L.length l > 0}) : GTot (list 'a) =
let l', _ = L.unsnoc l in l'
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_before'
val l_insert_before' (i: nat) (l: list 'a) (x: 'a) : GTot (list 'a)
val l_insert_before' (i: nat) (l: list 'a) (x: 'a) : GTot (list 'a)
let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 193, "start_col": 0, "start_line": 191 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> l: Prims.list 'a -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.list", "FStar.List.Tot.Base.append", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt" ]
[]
false
false
false
false
false
let l_insert_before' (i: nat) (l: list 'a) (x: 'a) : GTot (list 'a) =
let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2)
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_split_using
val l_split_using (l: list 'a) (x: 'a{x `L.memP` l}) : GTot (list 'a * list 'a)
val l_split_using (l: list 'a) (x: 'a{x `L.memP` l}) : GTot (list 'a * list 'a)
let l_split_using (l:list 'a) (x:'a{x `L.memP` l}) : GTot (list 'a * list 'a) = L.split_using l x
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 225, "start_col": 0, "start_line": 224 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2 let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> x: 'a{FStar.List.Tot.Base.memP x l} -> Prims.GTot (Prims.list 'a * Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.memP", "FStar.List.Tot.Properties.split_using", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let l_split_using (l: list 'a) (x: 'a{x `L.memP` l}) : GTot (list 'a * list 'a) =
L.split_using l x
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_append
val l_append (l1 l2: list 'a) : GTot (list 'a)
val l_append (l1 l2: list 'a) : GTot (list 'a)
let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 222, "start_col": 0, "start_line": 221 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list 'a -> l2: Prims.list 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.append" ]
[]
false
false
false
false
false
let l_append (l1 l2: list 'a) : GTot (list 'a) =
l1 `L.append` l2
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_split_using'
val l_split_using' (l: list 'a) (i: nat) : GTot (list 'a * list 'a)
val l_split_using' (l: list 'a) (i: nat) : GTot (list 'a * list 'a)
let l_split_using' (l:list 'a) (i:nat) : GTot (list 'a * list 'a) = L.splitAt i l
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 228, "start_col": 0, "start_line": 227 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2 let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2 let l_split_using (l:list 'a) (x:'a{x `L.memP` l}) : GTot (list 'a * list 'a) = L.split_using l x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a -> i: Prims.nat -> Prims.GTot (Prims.list 'a * Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.nat", "FStar.List.Tot.Base.splitAt", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let l_split_using' (l: list 'a) (i: nat) : GTot (list 'a * list 'a) =
L.splitAt i l
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.loc_equiv
val loc_equiv : a: LowStar.Monotonic.Buffer.loc -> b: LowStar.Monotonic.Buffer.loc -> Prims.logical
let loc_equiv (a b:B.loc) = B.loc_includes a b /\ B.loc_includes b a
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 233, "start_col": 0, "start_line": 232 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2 let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2 let l_split_using (l:list 'a) (x:'a{x `L.memP` l}) : GTot (list 'a * list 'a) = L.split_using l x let l_split_using' (l:list 'a) (i:nat) : GTot (list 'a * list 'a) = L.splitAt i l /// Useful "shortform" for equivalence of [loc]s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: LowStar.Monotonic.Buffer.loc -> b: LowStar.Monotonic.Buffer.loc -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_includes", "Prims.logical" ]
[]
false
false
false
true
true
let loc_equiv (a b: B.loc) =
B.loc_includes a b /\ B.loc_includes b a
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.fp_strictly_disjoint_union
val fp_strictly_disjoint_union : l: LowStar.Monotonic.Buffer.loc -> l1: LowStar.Monotonic.Buffer.loc -> l2: LowStar.Monotonic.Buffer.loc -> Prims.logical
let fp_strictly_disjoint_union (l l1 l2:B.loc) = l `loc_equiv` B.loc_union l1 l2 /\ l1 `B.loc_disjoint` l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 287, "start_col": 0, "start_line": 285 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2 let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2 let l_split_using (l:list 'a) (x:'a{x `L.memP` l}) : GTot (list 'a * list 'a) = L.split_using l x let l_split_using' (l:list 'a) (i:nat) : GTot (list 'a * list 'a) = L.splitAt i l /// Useful "shortform" for equivalence of [loc]s let loc_equiv (a b:B.loc) = B.loc_includes a b /\ B.loc_includes b a /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. val dll_insert_at_head (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_head (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_head (as_list h0 d) n)) val dll_insert_at_tail (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_tail (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_tail (as_list h0 d) n)) val dll_insert_before (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_before' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_before n' (as_list h0 d) n)) val dll_insert_after (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ L.length (as_payload_list h0 d) = L.length (as_list h0 d) /\ // TODO: Why?! as_payload_list h1 d == l_insert_after' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_after n' (as_list h0 d) n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: LowStar.Monotonic.Buffer.loc -> l1: LowStar.Monotonic.Buffer.loc -> l2: LowStar.Monotonic.Buffer.loc -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "Prims.l_and", "DoublyLinkedListIface.loc_equiv", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_disjoint", "Prims.logical" ]
[]
false
false
false
true
true
let fp_strictly_disjoint_union (l l1 l2: B.loc) =
l `loc_equiv` (B.loc_union l1 l2) /\ l1 `B.loc_disjoint` l2
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.aux_fp_split_by_node
val aux_fp_split_by_node : h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> Prims.logical
let aux_fp_split_by_node (h0 h1:HS.mem) (d:dll 'a) (n:node 'a) = fp_strictly_disjoint_union (fp_dll h0 d) (fp_dll h1 d) (fp_node n)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 68, "end_line": 291, "start_col": 0, "start_line": 290 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2 let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2 let l_append (l1 l2:list 'a) : GTot (list 'a) = l1 `L.append` l2 let l_split_using (l:list 'a) (x:'a{x `L.memP` l}) : GTot (list 'a * list 'a) = L.split_using l x let l_split_using' (l:list 'a) (i:nat) : GTot (list 'a * list 'a) = L.splitAt i l /// Useful "shortform" for equivalence of [loc]s let loc_equiv (a b:B.loc) = B.loc_includes a b /\ B.loc_includes b a /// Stateful DoublyLinkedList operations /// /// These are most likely what you want to be using when writing /// code. The rest of this interface lets you talk about these /// operations easily. val dll_insert_at_head (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_head (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_head (as_list h0 d) n)) val dll_insert_at_tail (#t:Type0) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d))) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_at_tail (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_at_tail (as_list h0 d) n)) val dll_insert_before (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ as_payload_list h1 d == l_insert_before' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_before n' (as_list h0 d) n)) val dll_insert_after (#t:Type0) (n':node t) (d:dll t) (n:node t) : HST.Stack unit (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ (fp_node n `B.loc_disjoint` fp_dll h0 d) /\ n' `L.memP` as_list h0 d)) (ensures (fun h0 () h1 -> B.modifies (fp_dll h1 d) h0 h1 /\ fp_dll h1 d `loc_equiv` B.loc_union (fp_dll h0 d) (fp_node n) /\ dll_valid h1 d /\ node_valid h1 n /\ L.length (as_payload_list h0 d) = L.length (as_list h0 d) /\ // TODO: Why?! as_payload_list h1 d == l_insert_after' (as_list h0 d `L.index_of` n') (as_payload_list h0 d) (g_node_val h0 n) /\ as_list h1 d == l_insert_after n' (as_list h0 d) n)) unfold let fp_strictly_disjoint_union (l l1 l2:B.loc) = l `loc_equiv` B.loc_union l1 l2 /\ l1 `B.loc_disjoint` l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> n: DoublyLinkedListIface.node 'a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "DoublyLinkedListIface.node", "DoublyLinkedListIface.fp_strictly_disjoint_union", "DoublyLinkedListIface.fp_dll", "DoublyLinkedListIface.fp_node", "Prims.logical" ]
[]
false
false
false
true
true
let aux_fp_split_by_node (h0 h1: HS.mem) (d: dll 'a) (n: node 'a) =
fp_strictly_disjoint_union (fp_dll h0 d) (fp_dll h1 d) (fp_node n)
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_before
val l_insert_before (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a)
val l_insert_before (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a)
let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 189, "start_col": 0, "start_line": 187 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x0: 'a -> l: Prims.list 'a {FStar.List.Tot.Base.memP x0 l} -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.memP", "FStar.List.Tot.Base.append", "Prims.Cons", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Properties.split_using" ]
[]
false
false
false
false
false
let l_insert_before (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a) =
let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2)
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_remove_head
val l_remove_head (l: list 'a {L.length l > 0}) : GTot (list 'a)
val l_remove_head (l: list 'a {L.length l > 0}) : GTot (list 'a)
let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l'
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 206, "start_col": 0, "start_line": 204 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a {FStar.List.Tot.Base.length l > 0} -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.b2t", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let l_remove_head (l: list 'a {L.length l > 0}) : GTot (list 'a) =
match l with | _ :: l' -> l'
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_after
val l_insert_after (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a)
val l_insert_after (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a)
let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 198, "start_col": 0, "start_line": 195 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x0: 'a -> l: Prims.list 'a {FStar.List.Tot.Base.memP x0 l} -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.memP", "FStar.List.Tot.Base.append", "Prims.Cons", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Properties.split_using", "FStar.List.Tot.Properties.lemma_split_using" ]
[]
false
false
false
false
false
let l_insert_after (x0: 'a) (l: list 'a {x0 `L.memP` l}) (x: 'a) : GTot (list 'a) =
let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2))
false
Vale.AsLowStar.MemoryHelpers.fst
Vale.AsLowStar.MemoryHelpers.down_up_buffer_read_reveal
val down_up_buffer_read_reveal (src:base_typ) (h:HS.mem) (s:ME.vale_heap) (b:(buf_t src src){B.live h b}) (i:nat{i < DV.length (get_downview b) / view_n src}) : Lemma (requires ( DV.length_eq (get_downview b); same_down_up_buffer_length src b; Seq.equal (LSig.nat_to_uint_seq_t src (ME.buffer_as_seq s (as_vale_buffer b))) (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ src))))) (ensures LSig.nat_to_uint src (ME.buffer_read (as_vale_buffer b) i s) == Seq.index (B.as_seq h b) i) [SMTPat (ME.buffer_read (as_vale_buffer b) i s); SMTPat (Seq.index (B.as_seq h b) i)]
val down_up_buffer_read_reveal (src:base_typ) (h:HS.mem) (s:ME.vale_heap) (b:(buf_t src src){B.live h b}) (i:nat{i < DV.length (get_downview b) / view_n src}) : Lemma (requires ( DV.length_eq (get_downview b); same_down_up_buffer_length src b; Seq.equal (LSig.nat_to_uint_seq_t src (ME.buffer_as_seq s (as_vale_buffer b))) (UV.as_seq h (UV.mk_buffer (get_downview b) (LSig.view_of_base_typ src))))) (ensures LSig.nat_to_uint src (ME.buffer_read (as_vale_buffer b) i s) == Seq.index (B.as_seq h b) i) [SMTPat (ME.buffer_read (as_vale_buffer b) i s); SMTPat (Seq.index (B.as_seq h b) i)]
let down_up_buffer_read_reveal src h s b i = let db = get_downview b in let n:pos = view_n src in let up_view = (LSig.view_of_base_typ src) in let ub = UV.mk_buffer db up_view in same_down_up_buffer_length src b; UV.length_eq ub; UV.get_sel h ub i; FStar.Math.Lemmas.lemma_mult_lt_right n i (DV.length db / n); FStar.Math.Lemmas.multiply_fractions (DV.length db) n; FStar.Math.Lemmas.nat_times_nat_is_nat i n; assert (low_buffer_read src src h b i == UV.View?.get up_view (Seq.slice (DV.as_seq h db) (i*n) (i*n + n))); DV.put_sel h db (i*n); let aux () : Lemma (n * ((i*n)/n) == i*n) = FStar.Math.Lemmas.cancel_mul_div i n in aux()
{ "file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 143, "start_col": 0, "start_line": 127 }
module Vale.AsLowStar.MemoryHelpers open FStar.Mul open Vale.Arch.HeapImpl open Vale.X64.MemoryAdapters open Vale.Interop.Base module B = LowStar.Buffer module UV = LowStar.BufferView.Up module DV = LowStar.BufferView.Down module ME = Vale.X64.Memory module VSig = Vale.AsLowStar.ValeSig module IX64 = Vale.Interop.X64 friend Vale.X64.Memory friend Vale.X64.Memory_Sems friend Vale.X64.Stack_i friend Vale.X64.Stack_Sems friend Vale.X64.Decls friend Vale.X64.StateLemmas friend Vale.X64.MemoryAdapters let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t) = let db = get_downview x in DV.length_eq db; UV.length_eq (UV.mk_buffer db (ME.uint_view t)) let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () let rec loc_eq (args:list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) = match args with | [] -> () | hd :: tl -> loc_eq tl let relate_modifies args m0 m1 = loc_eq args let reveal_readable #src #t x s = () let reveal_imm_readable #src #t x s = () let readable_live #src #t x s = () let readable_imm_live #src #t x s = () let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap //let get_heap_mk_mem_reveal args h0 = () let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let mk_stack_reveal stack = () let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap let buffer_as_seq_reveal2 src t x va_s = () let immbuffer_as_seq_reveal2 src t x va_s = () let buffer_addr_reveal src t x args h0 = () let immbuffer_addr_reveal src t x args h0 = () let fuel_eq = () let decls_eval_code_reveal c va_s0 va_s1 f = () let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = () let modifies_same_roots s h0 h1 = () let modifies_equal_domains s h0 h1 = () let loc_disjoint_sym x y = () #set-options "--z3rlimit 20" let core_create_lemma_taint_hyp #max_arity #arg_reg (args:IX64.arg_list) (h0:HS.mem{mem_roots_p h0 args}) : Lemma (ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in LSig.taint_hyp args va_s)) = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap; let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in let taint_map = full_heap_taint va_s.VS.vs_heap in let mem = ME.get_vale_heap va_s.VS.vs_heap in // assert (mem == mk_mem args h0); let raw_taint = IX64.(mk_taint args IX64.init_taint) in // assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint); ME.valid_memtaint mem (args_b8 args) raw_taint; // assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x)); Classical.forall_intro (IX64.mk_taint_equiv args); assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==> Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a)); Classical.forall_intro (args_b8_mem args); assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==> LSig.taint_hyp_arg mem taint_map x); BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args let buffer_writeable_reveal src t x = () let buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let imm_buffer_read_reveal src t h s b i = let db = get_downview b in DV.length_eq db; let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in UV.as_seq_sel h b_v i let buffer_as_seq_invert src t h s b = let db = get_downview b in DV.length_eq db; assert (Seq.equal (ME.buffer_as_seq s (as_vale_buffer b)) (LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t))))) let buffer_as_seq_reveal_tuint128 src x va_s = () let immbuffer_as_seq_reveal_tuint128 src x va_s = () let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred let same_down_up_buffer_length src b = let db = get_downview b in DV.length_eq db; FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src)
{ "checked_file": "/", "dependencies": [ "Vale.X64.StateLemmas.fst.checked", "Vale.X64.Stack_Sems.fst.checked", "Vale.X64.Stack_i.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.MemoryAdapters.fst.checked", "Vale.X64.Memory_Sems.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Memory.fst.checked", "Vale.X64.Decls.fst.checked", "Vale.Lib.BufferViewHelpers.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": true, "source_file": "Vale.AsLowStar.MemoryHelpers.fst" }
[ { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": true, "full_module": "Vale.Interop", "short_module": "I" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Vale.X64.Lemmas", "short_module": "VL" }, { "abbrev": true, "full_module": "Vale.X64.StateLemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_Sems", "short_module": "VSS" }, { "abbrev": true, "full_module": "Vale.X64.Stack_i", "short_module": "SI" }, { "abbrev": true, "full_module": "Vale.X64.Memory_Sems", "short_module": "MES" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": "BS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "Vale.AsLowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
src: Vale.Arch.HeapTypes_s.base_typ -> h: FStar.Monotonic.HyperStack.mem -> s: Vale.X64.Memory.vale_heap -> b: Vale.Interop.Base.buf_t src src {LowStar.Monotonic.Buffer.live h b} -> i: Prims.nat { i < LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) / Vale.Interop.Types.view_n src } -> FStar.Pervasives.Lemma (requires (LowStar.BufferView.Down.length_eq (Vale.Interop.Types.get_downview b); Vale.AsLowStar.MemoryHelpers.same_down_up_buffer_length src b; FStar.Seq.Base.equal (Vale.AsLowStar.LowStarSig.nat_to_uint_seq_t src (Vale.X64.Memory.buffer_as_seq s (Vale.X64.MemoryAdapters.as_vale_buffer b))) (LowStar.BufferView.Up.as_seq h (LowStar.BufferView.Up.mk_buffer (Vale.Interop.Types.get_downview b) (Vale.AsLowStar.LowStarSig.view_of_base_typ src))))) (ensures Vale.AsLowStar.LowStarSig.nat_to_uint src (Vale.X64.Memory.buffer_read (Vale.X64.MemoryAdapters.as_vale_buffer b) i s) == FStar.Seq.Base.index (LowStar.Monotonic.Buffer.as_seq h b) i) [ SMTPat (Vale.X64.Memory.buffer_read (Vale.X64.MemoryAdapters.as_vale_buffer b) i s); SMTPat (FStar.Seq.Base.index (LowStar.Monotonic.Buffer.as_seq h b) i) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "FStar.Monotonic.HyperStack.mem", "Vale.X64.Memory.vale_heap", "Vale.Interop.Base.buf_t", "LowStar.Monotonic.Buffer.live", "Vale.Interop.Types.base_typ_as_type", "LowStar.Buffer.trivial_preorder", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "LowStar.BufferView.Down.length", "FStar.UInt8.t", "Vale.Interop.Types.get_downview", "Vale.Interop.Types.view_n", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Multiply", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Math.Lemmas.cancel_mul_div", "FStar.Mul.op_Star", "LowStar.BufferView.Down.put_sel", "Prims._assert", "Vale.AsLowStar.MemoryHelpers.low_buffer_read", "LowStar.BufferView.Up.__proj__View__item__get", "FStar.Seq.Base.slice", "LowStar.BufferView.Down.as_seq", "Prims.op_Addition", "FStar.Math.Lemmas.nat_times_nat_is_nat", "FStar.Math.Lemmas.multiply_fractions", "FStar.Math.Lemmas.lemma_mult_lt_right", "LowStar.BufferView.Up.get_sel", "LowStar.BufferView.Up.length_eq", "Vale.AsLowStar.MemoryHelpers.same_down_up_buffer_length", "LowStar.BufferView.Up.buffer", "LowStar.BufferView.Up.mk_buffer", "LowStar.BufferView.Up.view", "Vale.AsLowStar.LowStarSig.view_of_base_typ", "Prims.pos", "LowStar.BufferView.Down.buffer" ]
[]
false
false
true
false
false
let down_up_buffer_read_reveal src h s b i =
let db = get_downview b in let n:pos = view_n src in let up_view = (LSig.view_of_base_typ src) in let ub = UV.mk_buffer db up_view in same_down_up_buffer_length src b; UV.length_eq ub; UV.get_sel h ub i; FStar.Math.Lemmas.lemma_mult_lt_right n i (DV.length db / n); FStar.Math.Lemmas.multiply_fractions (DV.length db) n; FStar.Math.Lemmas.nat_times_nat_is_nat i n; assert (low_buffer_read src src h b i == UV.View?.get up_view (Seq.slice (DV.as_seq h db) (i * n) (i * n + n))); DV.put_sel h db (i * n); let aux () : Lemma (n * ((i * n) / n) == i * n) = FStar.Math.Lemmas.cancel_mul_div i n in aux ()
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_insert_after'
val l_insert_after' (i: nat) (l: list 'a {i < L.length l}) (x: 'a) : GTot (list 'a)
val l_insert_after' (i: nat) (l: list 'a {i < L.length l}) (x: 'a) : GTot (list 'a)
let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 202, "start_col": 0, "start_line": 200 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> l: Prims.list 'a {i < FStar.List.Tot.Base.length l} -> x: 'a -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.nat", "Prims.list", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "FStar.List.Tot.Base.append", "Prims.Cons", "FStar.List.Tot.Base.index", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.unit", "FStar.List.Tot.Base.lemma_splitAt_snd_length" ]
[]
false
false
false
false
false
let l_insert_after' (i: nat) (l: list 'a {i < L.length l}) (x: 'a) : GTot (list 'a) =
let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2))
false
MerkleTree.Low.VectorExtras.fst
MerkleTree.Low.VectorExtras.move_left
val move_left (#a: _) (b: B.buffer a) (dst src l: U32.t) : HST.Stack unit (requires fun h0 -> B.live h0 b /\ U32.v src + U32.v l <= B.length b /\ U32.v dst <= U32.v src ) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ (let b0 = B.as_seq h0 b in let b1 = B.as_seq h1 b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in (S.slice b1 dst (dst + l)) `S.equal` (S.slice b0 src (src + l))))
val move_left (#a: _) (b: B.buffer a) (dst src l: U32.t) : HST.Stack unit (requires fun h0 -> B.live h0 b /\ U32.v src + U32.v l <= B.length b /\ U32.v dst <= U32.v src ) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ (let b0 = B.as_seq h0 b in let b1 = B.as_seq h1 b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in (S.slice b1 dst (dst + l)) `S.equal` (S.slice b0 src (src + l))))
let move_left #a (b: B.buffer a) (dst src: U32.t) (l: U32.t): HST.Stack unit (requires fun h0 -> B.live h0 b /\ U32.v src + U32.v l <= B.length b /\ U32.v dst <= U32.v src) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ ( let b0 = B.as_seq h0 b in let b1 = B.as_seq h1 b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in S.slice b1 dst (dst + l) `S.equal` S.slice b0 src (src + l))) = let h0 = HST.get () in [@inline_let] let inv (h: HS.mem) (i: nat) = let b0 = B.as_seq h0 b in let b1 = B.as_seq h b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in i <= l /\ B.(modifies (loc_buffer b) h0 h) /\ S.slice b1 dst (dst + i) `S.equal` S.slice b0 src (src + i) /\ S.slice b1 (src + i) (src + l) `S.equal` S.slice b0 (src + i) (src + l) in let f (i: U32.t { U32.(0 <= v i /\ v i < v l) }): HST.Stack unit (requires fun h0 -> inv h0 (U32.v i)) (ensures fun h0 _ h1 -> U32.(inv h0 (v i) /\ inv h1 (v i + 1))) = let h00 = HST.get () in calc (==) { S.index (B.as_seq h0 b) U32.(v src + v i); (==) {} S.index (S.slice (B.as_seq h0 b) U32.(v src + v i) U32.(v src + v l)) 0; (==) {} S.index (S.slice (B.as_seq h00 b) U32.(v src + v i) U32.(v src + v l)) 0; (==) {} S.index (B.as_seq h00 b) U32.(v src + v i); }; b.(dst `U32.add` i) <- b.(src `U32.add` i); let h = HST.get () in let b0 = B.as_seq h0 b in let b1 = B.as_seq h b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in let i = U32.v i in calc (S.equal) { S.slice b1 dst (dst + (i + 1)); (S.equal) { lemma_slice_ijk b1 dst (dst + i) (dst + i + 1) } S.slice b1 dst (dst + i) `S.append` S.slice b1 (dst + i) (dst + i + 1); (S.equal) { } S.slice b0 src (src + i) `S.append` S.slice b1 (dst + i) (dst + i + 1); (S.equal) { } S.slice b0 src (src + i) `S.append` S.cons (S.index b1 (dst + i)) S.empty; (S.equal) { } S.slice b0 src (src + i) `S.append` S.cons (S.index b0 (src + i)) S.empty; (S.equal) { } S.slice b0 src (src + i) `S.append` S.slice b0 (src + i) (src + i + 1); (S.equal) { lemma_slice_ijk b0 src (src + i) (src + i + 1) } S.slice b0 src (src + (i + 1)); }; let s1 = S.slice b1 (src + (i + 1)) (src + l) in let s0 = S.slice b0 (src + (i + 1)) (src + l) in let aux (j: nat { j < S.length s0 }): Lemma (S.index s0 j == S.index s1 j) [ SMTPat (S.index s0 j); SMTPat (S.index s1 j) ] = calc (==) { S.index s0 j; (==) {} S.index (S.slice b0 (src + i) (src + l)) (j + 1); (==) {} S.index (S.slice b1 (src + i) (src + l)) (j + 1); (==) {} S.index s1 j; } in () in C.Loops.for 0ul l inv f
{ "file_name": "src/MerkleTree.Low.VectorExtras.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 25, "end_line": 108, "start_col": 0, "start_line": 26 }
module MerkleTree.Low.VectorExtras module B = LowStar.Buffer module S = FStar.Seq module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 open LowStar.BufferOps open Hacl.Hash.Lemmas open FStar.Integers open LowStar.Modifies open LowStar.Regional open LowStar.Vector open LowStar.RVector module V = LowStar.Vector module RV = LowStar.RVector (** Some extra functions on top of LowStar.Vector... used for Merkle Tree. *) #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Hacl.Hash.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Calc.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.VectorExtras.fst" }
[ { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowStar.Buffer.buffer a -> dst: FStar.UInt32.t -> src: FStar.UInt32.t -> l: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt32.t", "C.Loops.for", "FStar.UInt32.__uint_to_t", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.op_LessThan", "FStar.Monotonic.HyperStack.mem", "Prims.op_Addition", "FStar.Integers.op_Less_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.op_Less", "FStar.Integers.int_t", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Seq.Base.index", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "FStar.Integers.nat", "FStar.Calc.calc_finish", "FStar.Preorder.relation", "FStar.Calc.calc_step", "FStar.Seq.Base.slice", "FStar.Integers.op_Plus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Seq.Base.seq", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.Seq.Base.cons", "FStar.Seq.Base.empty", "Hacl.Hash.Lemmas.lemma_slice_ijk", "FStar.UInt.uint_t", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Buffer.trivial_preorder", "FStar.HyperStack.ST.get", "LowStar.BufferOps.op_Array_Assignment", "FStar.UInt32.add", "LowStar.BufferOps.op_Array_Access", "Prims.logical", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.length" ]
[]
false
true
false
false
false
let move_left #a (b: B.buffer a) (dst: U32.t) (src: U32.t) (l: U32.t) : HST.Stack unit (requires fun h0 -> B.live h0 b /\ U32.v src + U32.v l <= B.length b /\ U32.v dst <= U32.v src ) (ensures fun h0 _ h1 -> B.(modifies (loc_buffer b) h0 h1) /\ (let b0 = B.as_seq h0 b in let b1 = B.as_seq h1 b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in (S.slice b1 dst (dst + l)) `S.equal` (S.slice b0 src (src + l)))) =
let h0 = HST.get () in [@@ inline_let ]let inv (h: HS.mem) (i: nat) = let b0 = B.as_seq h0 b in let b1 = B.as_seq h b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in i <= l /\ B.(modifies (loc_buffer b) h0 h) /\ (S.slice b1 dst (dst + i)) `S.equal` (S.slice b0 src (src + i)) /\ (S.slice b1 (src + i) (src + l)) `S.equal` (S.slice b0 (src + i) (src + l)) in let f (i: U32.t{let open U32 in 0 <= v i /\ v i < v l}) : HST.Stack unit (requires fun h0 -> inv h0 (U32.v i)) (ensures fun h0 _ h1 -> let open U32 in inv h0 (v i) /\ inv h1 (v i + 1)) = let h00 = HST.get () in calc ( == ) { S.index (B.as_seq h0 b) U32.(v src + v i); ( == ) { () } S.index (S.slice (B.as_seq h0 b) U32.(v src + v i) U32.(v src + v l)) 0; ( == ) { () } S.index (S.slice (B.as_seq h00 b) U32.(v src + v i) U32.(v src + v l)) 0; ( == ) { () } S.index (B.as_seq h00 b) U32.(v src + v i); }; b.(dst `U32.add` i) <- b.(src `U32.add` i); let h = HST.get () in let b0 = B.as_seq h0 b in let b1 = B.as_seq h b in let src = U32.v src in let dst = U32.v dst in let l = U32.v l in let i = U32.v i in calc (S.equal) { S.slice b1 dst (dst + (i + 1)); (S.equal) { lemma_slice_ijk b1 dst (dst + i) (dst + i + 1) } (S.slice b1 dst (dst + i)) `S.append` (S.slice b1 (dst + i) (dst + i + 1)); (S.equal) { () } (S.slice b0 src (src + i)) `S.append` (S.slice b1 (dst + i) (dst + i + 1)); (S.equal) { () } (S.slice b0 src (src + i)) `S.append` (S.cons (S.index b1 (dst + i)) S.empty); (S.equal) { () } (S.slice b0 src (src + i)) `S.append` (S.cons (S.index b0 (src + i)) S.empty); (S.equal) { () } (S.slice b0 src (src + i)) `S.append` (S.slice b0 (src + i) (src + i + 1)); (S.equal) { lemma_slice_ijk b0 src (src + i) (src + i + 1) } S.slice b0 src (src + (i + 1)); }; let s1 = S.slice b1 (src + (i + 1)) (src + l) in let s0 = S.slice b0 (src + (i + 1)) (src + l) in let aux (j: nat{j < S.length s0}) : Lemma (S.index s0 j == S.index s1 j) [SMTPat (S.index s0 j); SMTPat (S.index s1 j)] = calc ( == ) { S.index s0 j; ( == ) { () } S.index (S.slice b0 (src + i) (src + l)) (j + 1); ( == ) { () } S.index (S.slice b1 (src + i) (src + l)) (j + 1); ( == ) { () } S.index s1 j; } in () in C.Loops.for 0ul l inv f
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_remove_mid'
val l_remove_mid' (l: list 'a {L.length l > 0}) (i: nat{i < L.length l}) : GTot (list 'a)
val l_remove_mid' (l: list 'a {L.length l > 0}) (i: nat{i < L.length l}) : GTot (list 'a)
let l_remove_mid' (l:list 'a{L.length l > 0}) (i:nat{i < L.length l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 219, "start_col": 0, "start_line": 217 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l' let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a {FStar.List.Tot.Base.length l > 0} -> i: Prims.nat{i < FStar.List.Tot.Base.length l} -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.b2t", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length", "Prims.nat", "Prims.op_LessThan", "FStar.List.Tot.Base.append", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.unit", "FStar.List.Tot.Base.lemma_splitAt_snd_length" ]
[]
false
false
false
false
false
let l_remove_mid' (l: list 'a {L.length l > 0}) (i: nat{i < L.length l}) : GTot (list 'a) =
let l1, x0 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` l2
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.g_node_vals
val g_node_vals (h: HS.mem) (l: list (node 'a)) : GTot (list 'a)
val g_node_vals (h: HS.mem) (l: list (node 'a)) : GTot (list 'a)
let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 87, "start_col": 0, "start_line": 84 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> l: Prims.list (DoublyLinkedListIface.node 'a) -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "Prims.list", "DoublyLinkedListIface.node", "Prims.Nil", "Prims.Cons", "DoublyLinkedListIface.g_node_val", "DoublyLinkedListIface.g_node_vals" ]
[ "recursion" ]
false
false
false
false
false
let rec g_node_vals (h: HS.mem) (l: list (node 'a)) : GTot (list 'a) =
match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl
false
DoublyLinkedListIface.fsti
DoublyLinkedListIface.l_remove_mid
val l_remove_mid (l: list 'a {L.length l > 0}) (x: 'a{x `L.memP` l}) : GTot (list 'a)
val l_remove_mid (l: list 'a {L.length l > 0}) (x: 'a{x `L.memP` l}) : GTot (list 'a)
let l_remove_mid (l:list 'a{L.length l > 0}) (x:'a {x `L.memP` l}) : GTot (list 'a) = let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 215, "start_col": 0, "start_line": 212 }
(* 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 DoublyLinkedListIface module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module L = FStar.List.Tot module B = LowStar.Buffer /// Abstract types defined by this library (** A singular node which stores a value of type [a] *) val node (a:Type0) : Type0 (** A doublylinkedlist of elements of type [a] *) val dll (a:Type0) : Type0 /// Abstract Validity Predicates val node_valid (h:HS.mem) (n:node 'a) : prop val dll_valid (h:HS.mem) (d:dll 'a) : prop /// Abstract node and list footprints val fp_node (n:node 'a) : GTot B.loc val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc /// Getters and setters for [node]s val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a val node_val (n:node 'a) : HST.StackInline 'a (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 v h1 -> h0 == h1 /\ v == g_node_val h0 n)) val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n)) /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop /// Be able to modify the payload of a node easily, without affecting /// membership val node_update (n:node 'a) (v:'a) : HST.StackInline (unit) (requires (fun h0 -> node_valid h0 n)) (ensures (fun h0 () h1 -> B.modifies (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n /\ unchanged_node_connections h0 h1 n)) /// Viewing ghostly state of a DoublyLinkedList as a list of nodes, /// and as list of payloads val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a)) let rec g_node_vals (h:HS.mem) (l:list (node 'a)) : GTot (list 'a) = match l with | [] -> [] | hd :: tl -> g_node_val h hd :: g_node_vals h tl let as_payload_list (h:HS.mem) (d:dll 'a) : GTot (list 'a) = g_node_vals h (as_list h d) /// Creating an empty DoublyLinkedList, and quickly accessing the head /// and tail of a DoublyLinkedList val dll_new (u:unit) : HST.StackInline (dll 'a) (requires (fun h0 -> True)) (ensures (fun h0 d h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_dll h1 d) h0 h1 /\ dll_valid h1 d /\ as_list h1 d == [])) val is_empty (d:dll 'a) : HST.StackInline (bool) (requires (fun h0 -> dll_valid h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> as_list h0 d == []))) val dll_head (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == L.hd (as_list h0 d))) val dll_tail (d:dll 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ L.length (as_list h0 d) > 0)) (ensures (fun h0 n h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n == snd (L.unsnoc (as_list h0 d)))) /// Moving forwards or backwards in a list val has_next (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1))) val has_prev (d:dll 'a) (n:node 'a) : HST.StackInline bool (requires (fun h0 -> dll_valid h0 d /\ node_valid h0 n /\ n `L.memP` as_list h0 d)) (ensures (fun h0 y h1 -> (h0 == h1) /\ (y <==> L.index_of (as_list h0 d) n > 0))) val next_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n < L.length (as_list h0 d) - 1)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n + 1))) val prev_node (d:dll 'a) (n:node 'a) : HST.StackInline (node 'a) (requires (fun h0 -> dll_valid h0 d /\ n `L.memP` as_list h0 d /\ L.index_of (as_list h0 d) n > 0)) (ensures (fun h0 n' h1 -> h0 == h1 /\ dll_valid h1 d /\ node_valid h1 n /\ as_list h0 d == as_list h1 d /\ n' == L.index (as_list h0 d) (L.index_of (as_list h0 d) n - 1))) /// DoublyLinkedList operations on standard [list]s instead let l_insert_at_head (l:list 'a) (x:'a) : GTot (list 'a) = x :: l let l_insert_at_tail (l:list 'a) (x:'a) : GTot (list 'a) = L.snoc (l, x) let l_insert_before (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, l2 = L.split_using l x0 in l1 `L.append` (x :: l2) let l_insert_before' (i:nat) (l:list 'a) (x:'a) : GTot (list 'a) = let l1, l2 = L.splitAt i l in l1 `L.append` (x :: l2) let l_insert_after (x0:'a) (l:list 'a{x0 `L.memP` l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_split_using l x0; L.split_using l x0 in assert (x0 == x1); l1 `L.append` (x0 :: (x :: l2)) let l_insert_after' (i:nat) (l:list 'a{i < L.length l}) (x:'a) : GTot (list 'a) = let l1, x1 :: l2 = L.lemma_splitAt_snd_length i l; L.splitAt i l in l1 `L.append` ((L.index l i) :: (x :: l2)) let l_remove_head (l:list 'a{L.length l > 0}) : GTot (list 'a) = match l with | _ :: l' -> l' let l_remove_tail (l:list 'a{L.length l > 0}) : GTot (list 'a) = let l', _ = L.unsnoc l in l'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Buffer.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "DoublyLinkedListIface.fsti" }
[ { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list 'a {FStar.List.Tot.Base.length l > 0} -> x: 'a{FStar.List.Tot.Base.memP x l} -> Prims.GTot (Prims.list 'a)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "Prims.b2t", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length", "FStar.List.Tot.Base.memP", "FStar.List.Tot.Base.append", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Properties.split_using", "FStar.List.Tot.Properties.lemma_split_using" ]
[]
false
false
false
false
false
let l_remove_mid (l: list 'a {L.length l > 0}) (x: 'a{x `L.memP` l}) : GTot (list 'a) =
let l1, x0 :: l2 = L.lemma_split_using l x; L.split_using l x in assert (x == x0); l1 `L.append` l2
false
FStar.OrdMap.fsti
FStar.OrdMap.cmp
val cmp : a: Prims.eqtype -> Type0
let cmp (a:eqtype) = f:(a -> a -> Tot bool){total_order a f}
{ "file_name": "ulib/experimental/FStar.OrdMap.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 26, "start_col": 0, "start_line": 26 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.OrdMap open FStar.OrdSet (* TODO (KM) : move me this should go in a common file on relations *) type total_order (a:eqtype) (f: (a -> a -> Tot bool)) = (forall a1 a2. (f a1 a2 /\ f a2 a1) ==> a1 = a2) (* anti-symmetry *) /\ (forall a1 a2 a3. f a1 a2 /\ f a2 a3 ==> f a1 a3) (* transitivity *) /\ (forall a1 a2. f a1 a2 \/ f a2 a1) (* totality *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.OrdSet.fsti.checked" ], "interface_file": false, "source_file": "FStar.OrdMap.fsti" }
[ { "abbrev": false, "full_module": "FStar.OrdSet", "short_module": null }, { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.eqtype -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "Prims.bool", "FStar.OrdMap.total_order" ]
[]
false
false
false
true
true
let cmp (a: eqtype) =
f: (a -> a -> Tot bool){total_order a f}
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_small_reg_name
val print_small_reg_name (r: reg_64) : string
val print_small_reg_name (r: reg_64) : string
let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl."
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 70, "end_line": 68, "start_col": 0, "start_line": 62 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Prims.int", "Prims.string" ]
[]
false
false
false
true
false
let print_small_reg_name (r: reg_64) : string =
match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl."
false
Hacl.HPKE.P256_CP256_SHA256.fsti
Hacl.HPKE.P256_CP256_SHA256.cs
val cs:S.ciphersuite
val cs:S.ciphersuite
let cs:S.ciphersuite = (DH.DH_P256, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256)
{ "file_name": "code/hpke/Hacl.HPKE.P256_CP256_SHA256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 96, "end_line": 10, "start_col": 0, "start_line": 10 }
module Hacl.HPKE.P256_CP256_SHA256 open Hacl.Impl.HPKE module S = Spec.Agile.HPKE module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash
{ "checked_file": "/", "dependencies": [ "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Hacl.Impl.HPKE.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.P256_CP256_SHA256.fsti" }
[ { "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 } ]
{ "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Agile.HPKE.ciphersuite
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.Mktuple4", "Spec.Agile.DH.algorithm", "Spec.Agile.HPKE.hash_algorithm", "Spec.Agile.HPKE.aead", "Spec.Hash.Definitions.hash_alg", "Spec.Agile.DH.DH_P256", "Spec.Hash.Definitions.SHA2_256", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305" ]
[]
false
false
false
true
false
let cs:S.ciphersuite =
(DH.DH_P256, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256)
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_reg64
val print_reg64 (r: reg_64) (p: printer) : string
val print_reg64 (r: reg_64) (p: printer) : string
let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 71, "start_col": 0, "start_line": 70 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl."
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.printer", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__print_reg_name", "Prims.string" ]
[]
false
false
false
true
false
let print_reg64 (r: reg_64) (p: printer) : string =
p.reg_prefix () ^ p.print_reg_name r
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_reg32_name
val print_reg32_name (r: reg_64) : string
val print_reg32_name (r: reg_64) : string
let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 60, "start_col": 0, "start_line": 50 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Prims.int", "Prims.op_Hat", "Vale.X64.Print_s.print_reg_name", "Prims.string" ]
[]
false
false
false
true
false
let print_reg32_name (r: reg_64) : string =
match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d"
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_reg32
val print_reg32 (r: reg_64) (p: printer) : string
val print_reg32 (r: reg_64) (p: printer) : string
let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 74, "start_col": 0, "start_line": 73 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.printer", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__print_reg32_name", "Prims.string" ]
[]
false
false
false
true
false
let print_reg32 (r: reg_64) (p: printer) : string =
p.reg_prefix () ^ p.print_reg32_name r
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_small_reg
val print_small_reg (r: reg_64) (p: printer) : string
val print_small_reg (r: reg_64) (p: printer) : string
let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 77, "start_col": 0, "start_line": 76 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.printer", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__print_small_reg_name", "Prims.string" ]
[]
false
false
false
true
false
let print_small_reg (r: reg_64) (p: printer) : string =
p.reg_prefix () ^ p.print_small_reg_name r
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_xmm
val print_xmm (x: reg_xmm) (p: printer) : string
val print_xmm (x: reg_xmm) (p: printer) : string
let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 124, "start_col": 0, "start_line": 123 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.X64.Machine_s.reg_xmm -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_xmm", "Vale.X64.Print_s.printer", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Prims.string_of_int", "Prims.string" ]
[]
false
false
false
true
false
let print_xmm (x: reg_xmm) (p: printer) : string =
p.reg_prefix () ^ "xmm" ^ string_of_int x
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_pair
val print_pair (dst src: string) (p: printer) : string
val print_pair (dst src: string) (p: printer) : string
let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 156, "start_col": 0, "start_line": 154 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o))
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dst: Prims.string -> src: Prims.string -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Vale.X64.Print_s.printer", "Prims.op_Hat", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order" ]
[]
false
false
false
true
false
let print_pair (dst src: string) (p: printer) : string =
let first, second = p.op_order dst src in first ^ ", " ^ second
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_imm8
val print_imm8 (i: int) (p: printer) : string
val print_imm8 (i: int) (p: printer) : string
let print_imm8 (i:int) (p:printer) : string = p.const i
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 121, "start_col": 0, "start_line": 120 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl."
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.X64.Print_s.printer", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Prims.string" ]
[]
false
false
false
true
false
let print_imm8 (i: int) (p: printer) : string =
p.const i
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_proc
val print_proc (name: string) (code: code) (label: int) (p: printer) : FStar.All.ML int
val print_proc (name: string) (code: code) (label: int) (p: printer) : FStar.All.ML int
let print_proc (name:string) (code:code) (label:int) (p:printer) : FStar.All.ML int = let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 296, "start_col": 0, "start_line": 291 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n') let print_header (p:printer) = print_string (p.header())
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> code: Vale.X64.Machine_Semantics_s.code -> label: Prims.int -> p: Vale.X64.Print_s.printer -> FStar.All.ML Prims.int
FStar.All.ML
[ "ml" ]
[]
[ "Prims.string", "Vale.X64.Machine_Semantics_s.code", "Prims.int", "Vale.X64.Print_s.printer", "Prims.unit", "FStar.IO.print_string", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__ret", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.print_code", "Vale.X64.Print_s.__proj__Mkprinter__item__proc_name" ]
[]
false
true
false
false
false
let print_proc (name: string) (code: code) (label: int) (p: printer) : FStar.All.ML int =
let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_header
val print_header : p: Vale.X64.Print_s.printer -> FStar.All.ML Prims.unit
let print_header (p:printer) = print_string (p.header())
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 289, "start_col": 0, "start_line": 288 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n')
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Vale.X64.Print_s.printer -> FStar.All.ML Prims.unit
FStar.All.ML
[ "ml" ]
[]
[ "Vale.X64.Print_s.printer", "FStar.IO.print_string", "Vale.X64.Print_s.__proj__Mkprinter__item__header", "Prims.unit" ]
[]
false
true
false
false
false
let print_header (p: printer) =
print_string (p.header ())
false
TwoLockQueue.fst
TwoLockQueue.dequeue
val dequeue (#a: _) (hdl: t a) : SteelT (option a) emp (fun _ -> emp)
val dequeue (#a: _) (hdl: t a) : SteelT (option a) emp (fun _ -> emp)
let dequeue (#a:_) (hdl:t a) : SteelT (option a) emp (fun _ -> emp) = // Blocks until it can acquire the head lock, corresponding to the dequeuer Steel.SpinLock.acquire hdl.head.lock; let v = open_exists () in let hd = read_pt hdl.head.ptr in // Executes the atomic dequeue, preserving the global queue invariant let o = with_invariant hdl.inv (dequeue_core hdl hd) in match o with | None -> // Dequeue failed, restore the dequeuer's ghost state rewrite_slprop (maybe_ghost_pts_to hdl.head.ghost hd o) (ghost_pts_to hdl.head.ghost half hd) (fun _ -> ()); intro_exists _ (fun v -> pts_to hdl.head.ptr full v `star` ghost_pts_to hdl.head.ghost half v); // Finally release the dequeuer lock Steel.SpinLock.release hdl.head.lock; None | Some next -> // Dequeue succeeded let open FStar.Tactics in assert (maybe_ghost_pts_to hdl.head.ghost hd (Some next) == ghost_pts_to hdl.head.ghost half next `star` h_exists (pts_to hd full_perm)) by (norm [delta; iota; zeta]); rewrite_slprop (maybe_ghost_pts_to hdl.head.ghost hd o) (ghost_pts_to hdl.head.ghost half next `star` h_exists (pts_to hd full_perm)) (fun _ -> ()); let c = open_exists () in // Update the concrete head pointer to the new head of the queue write_pt hdl.head.ptr next; // Repack the dequeuer lock invariant intro_exists _ (fun v -> pts_to hdl.head.ptr full v `star` ghost_pts_to hdl.head.ghost half v); // Release the dequeuer lock Steel.SpinLock.release hdl.head.lock; // Free the now unneeded pointer to the next element in the dequeued cell let c = read_pt hd in let v = c.Q.data in free_pt hd; Some v
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 297, "start_col": 0, "start_line": 258 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q) let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in () let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : SteelGhostT (Ghost.erased a) opened_invariants (h_exists p) (fun r -> p (reveal r)) = let v : erased a = witness_exists () in v (*** Queue invariant ***) /// The invariant associated to the lock. Basically a variant of the /// Owicki-Gries invariant, but applied to queues [@@__reduce__] let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) = h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) let intro_lock_inv #a #u (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (fun _ -> lock_inv ptr ghost) = assert_spinoff (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (lock_inv _ _) (fun _ -> ()) /// The type of a queue pointer. /// Contains the concrete pointer [ptr], the pointer to ghost state [ghost], /// and a lock [lock] protecting the invariant relating the concrete and ghost states noeq type q_ptr (a:Type) = { ptr : ref (Q.t a); ghost: ghost_ref (Q.t a); lock: lock (lock_inv ptr ghost); } /// The global queue invariant, which will be shared by the enqueuer and the dequeuer. /// Again, inspired by the Owicki-Gries counter: It contains half the permission for the ghost /// state of the enqueuer and dequeuer, while ensuring that the concrete queue always remains /// a valid queue let queue_invariant (#a:_) ([@@@smt_fallback]head:q_ptr a) ([@@@smt_fallback] tail:q_ptr a) = h_exists (fun (h:Q.t a) -> h_exists (fun (t:Q.t a) -> ghost_pts_to head.ghost half h `star` ghost_pts_to tail.ghost half t `star` Q.queue h t)) let pack_queue_invariant (#a:_) (#u:_) (x:erased (Q.t a)) (y:erased (Q.t a)) (head tail:q_ptr a) : SteelGhostT unit u (ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y) (fun _ -> queue_invariant head tail) = intro_exists (reveal y) (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y); intro_exists (reveal x) (fun x -> h_exists (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y)) /// The type of a queue. It contains a head and tail pointers, each with their own ghost state, /// as well as the global queue invariant [inv]. Note that compared to the locks in the head and tail /// pointers with type `q_ptr`, since invariant is a true Steel invariant, only accessible inside /// atomic computations noeq type t (a:Type0) = { head : q_ptr a; tail : q_ptr a; inv : inv (queue_invariant head tail) } /// Creating a new queue. let new_queue (#a:_) (x:a) : SteelT (t a) emp (fun _ -> emp) = let new_qptr (#a:_) (q:Q.t a) : SteelT (q_ptr a) emp (fun qp -> ghost_pts_to qp.ghost half q) = // Allocates the concrete pointer. let ptr = alloc_pt q in // Allocates the ghost state, and sets the corresponding lock invariant let ghost = ghost_alloc_pt q in ghost_share_pt ghost; intro_exists _ (fun q -> pts_to ptr full q `star` ghost_pts_to ghost half q); let lock = Steel.SpinLock.new_lock _ in { ptr; ghost; lock} in // Creating a concrete queue let hd = Q.new_queue x in // Creating the head and queue pointers let head = new_qptr hd in let tail = new_qptr hd in // Creating the global queue invariant pack_queue_invariant (hide hd) (hide hd) head tail; let inv = new_invariant _ in // Packing the different components to return a queue, as defined in type `t` return ({ head; tail; inv }) #restart-solver /// Enqueues element [x] in the queue [hdl] let enqueue (#a:_) (hdl:t a) (x:a) : SteelT unit emp (fun _ -> emp) = // Blocks until it can acquire the tail lock corresponding to the enqueuer Steel.SpinLock.acquire hdl.tail.lock; let cell = Q.({ data = x; next = null} ) in let v:erased (Q.t a) = open_exists () in let tl = read_pt hdl.tail.ptr in // Creates a new cell for the enqueued element let node = alloc_pt cell in // Core, atomic enqueue function, calling the concrete enqueue function while also // modifying ghost state to preserve the invariants let enqueue_core #u () : SteelAtomicT unit u (queue_invariant hdl.head hdl.tail `star` (ghost_pts_to hdl.tail.ghost half tl `star` pts_to node full cell)) (fun _ -> queue_invariant hdl.head hdl.tail `star` ghost_pts_to hdl.tail.ghost half node) = let open FStar.Ghost in let h = open_exists () in let t = open_exists () in ghost_gather tl hdl.tail.ghost; Q.enqueue tl node; ghost_write_pt hdl.tail.ghost node; ghost_share_pt #_ #_ hdl.tail.ghost; pack_queue_invariant h (hide node) hdl.head hdl.tail; return () in // Actually executing the atomic enqueue operation while preserving the global queue invariant let r1 = with_invariant hdl.inv enqueue_core in // Updates the queue tail pointer let r2 = write_pt hdl.tail.ptr node in // Updates the queue tail ghost state let r3 = intro_exists _ (fun (n:(Q.t a)) -> pts_to hdl.tail.ptr full_perm n `star` ghost_pts_to hdl.tail.ghost half n) in // Releases the tail lock corresponding to the enqueuer Steel.SpinLock.release hdl.tail.lock let maybe_ghost_pts_to #a (x:ghost_ref (Q.t a)) ([@@@ smt_fallback] hd:Q.t a) (o:option (Q.t a)) = match o with | None -> ghost_pts_to x half hd | Some next -> ghost_pts_to x half next `star` (h_exists (pts_to hd full_perm)) /// Actual atomic dequeue operation, preserving the global queue invariant. let dequeue_core (#a:_) (#u:_) (hdl:t a) (hd:Q.t a) (_:unit) : SteelAtomicT (option (Q.t a)) u (queue_invariant hdl.head hdl.tail `star` ghost_pts_to hdl.head.ghost half hd) (fun o -> queue_invariant hdl.head hdl.tail `star` maybe_ghost_pts_to hdl.head.ghost hd o) = let h = open_exists () in let t = open_exists () in ghost_gather hd hdl.head.ghost; // Attempts a concrete dequeue let o = Queue.dequeue hd in match o with | None -> // The list was empty, dequeue failed. We repack the invariant rewrite (Q.dequeue_post _ _ _) (Q.queue hd t); ghost_share_pt hdl.head.ghost; pack_queue_invariant hd t hdl.head hdl.tail; rewrite (ghost_pts_to hdl.head.ghost _ _) (maybe_ghost_pts_to _ _ _); return o | Some p -> // dequeue succeeded, and returned element p rewrite (Q.dequeue_post _ _ _) (Q.dequeue_post_success _ _ _); let c = open_exists () in elim_pure (); intro_exists (reveal c) (pts_to hd full_perm); // Updates the head ghost state ghost_write_pt hdl.head.ghost p; ghost_share_pt hdl.head.ghost; // Repack the global queue invariant pack_queue_invariant _ _ hdl.head hdl.tail; assert (maybe_ghost_pts_to hdl.head.ghost hd (Some p) == ghost_pts_to hdl.head.ghost half p `star` h_exists (pts_to hd full_perm)) by (FStar.Tactics.norm [delta; iota; zeta]); rewrite (ghost_pts_to hdl.head.ghost half p `star` h_exists (pts_to hd full_perm)) (maybe_ghost_pts_to hdl.head.ghost hd o); return o
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hdl: TwoLockQueue.t a -> Steel.Effect.SteelT (FStar.Pervasives.Native.option a)
Steel.Effect.SteelT
[]
[]
[ "TwoLockQueue.t", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.unit", "Steel.SpinLock.release", "TwoLockQueue.lock_inv", "TwoLockQueue.__proj__Mkq_ptr__item__ptr", "TwoLockQueue.__proj__Mkt__item__head", "TwoLockQueue.__proj__Mkq_ptr__item__ghost", "TwoLockQueue.__proj__Mkq_ptr__item__lock", "Steel.Effect.Atomic.intro_exists", "Queue.Def.t", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.Reference.pts_to", "TwoLockQueue.full", "Steel.Reference.ghost_pts_to", "TwoLockQueue.half", "Steel.Effect.Common.vprop", "Steel.Effect.Atomic.rewrite_slprop", "TwoLockQueue.maybe_ghost_pts_to", "Steel.Memory.mem", "FStar.Pervasives.Native.Some", "Steel.Reference.free_pt", "Queue.Def.cell", "Queue.Def.__proj__Mkcell__item__data", "Steel.Reference.read_pt", "Steel.FractionalPermission.full_perm", "Steel.Reference.write_pt", "FStar.Ghost.erased", "TwoLockQueue.open_exists", "Steel.Effect.Atomic.h_exists", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "Prims.Nil", "Steel.Effect.Atomic.with_invariant", "Steel.Effect.Common.Observable", "TwoLockQueue.queue_invariant", "TwoLockQueue.__proj__Mkt__item__tail", "TwoLockQueue.__proj__Mkt__item__inv", "TwoLockQueue.dequeue_core", "Steel.Effect.Common.add_inv", "Steel.Effect.Common.VStar", "Steel.FractionalPermission.half_perm", "Steel.SpinLock.acquire", "Steel.Effect.Common.emp" ]
[]
false
true
false
false
false
let dequeue (#a: _) (hdl: t a) : SteelT (option a) emp (fun _ -> emp) =
Steel.SpinLock.acquire hdl.head.lock; let v = open_exists () in let hd = read_pt hdl.head.ptr in let o = with_invariant hdl.inv (dequeue_core hdl hd) in match o with | None -> rewrite_slprop (maybe_ghost_pts_to hdl.head.ghost hd o) (ghost_pts_to hdl.head.ghost half hd) (fun _ -> ()); intro_exists _ (fun v -> (pts_to hdl.head.ptr full v) `star` (ghost_pts_to hdl.head.ghost half v)); Steel.SpinLock.release hdl.head.lock; None | Some next -> let open FStar.Tactics in FStar.Tactics.Effect.assert_by_tactic (maybe_ghost_pts_to hdl.head.ghost hd (Some next) == (ghost_pts_to hdl.head.ghost half next) `star` (h_exists (pts_to hd full_perm))) (fun _ -> (); (norm [delta; iota; zeta])); rewrite_slprop (maybe_ghost_pts_to hdl.head.ghost hd o) ((ghost_pts_to hdl.head.ghost half next) `star` (h_exists (pts_to hd full_perm))) (fun _ -> ()); let c = open_exists () in write_pt hdl.head.ptr next; intro_exists _ (fun v -> (pts_to hdl.head.ptr full v) `star` (ghost_pts_to hdl.head.ghost half v)); Steel.SpinLock.release hdl.head.lock; let c = read_pt hd in let v = c.Q.data in free_pt hd; Some v
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_reg_name
val print_reg_name (r: reg_64) : string
val print_reg_name (r: reg_64) : string
let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 48, "start_col": 0, "start_line": 31 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; }
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg_64 -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Prims.string" ]
[]
false
false
false
true
false
let print_reg_name (r: reg_64) : string =
match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15"
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_footer
val print_footer : p: Vale.X64.Print_s.printer -> FStar.All.ML Prims.unit
let print_footer (p:printer) = print_string (p.footer())
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 299, "start_col": 0, "start_line": 298 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n') let print_header (p:printer) = print_string (p.header()) let print_proc (name:string) (code:code) (label:int) (p:printer) : FStar.All.ML int = let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Vale.X64.Print_s.printer -> FStar.All.ML Prims.unit
FStar.All.ML
[ "ml" ]
[]
[ "Vale.X64.Print_s.printer", "FStar.IO.print_string", "Vale.X64.Print_s.__proj__Mkprinter__item__footer", "Prims.unit" ]
[]
false
true
false
false
false
let print_footer (p: printer) =
print_string (p.footer ())
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_operand
val print_operand (o: operand64) (p: printer) : string
val print_operand (o: operand64) (p: printer) : string
let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 102, "start_col": 0, "start_line": 96 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.nat64", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.X64.Machine_s.pow2_64", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Prims.bool", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.print_reg64", "Vale.X64.Machine_s.maddr", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Print_s.print_maddr", "Vale.X64.Print_s.print_reg_int" ]
[]
false
false
false
true
false
let print_operand (o: operand64) (p: printer) : string =
match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_reg_int
val print_reg_int (r: reg) (p: printer) : string
val print_reg_int (r: reg) (p: printer) : string
let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 94, "start_col": 0, "start_line": 91 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.X64.Machine_s.reg -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.reg_id", "Vale.X64.Print_s.print_reg64", "Prims.string" ]
[]
false
false
false
true
false
let print_reg_int (r: reg) (p: printer) : string =
match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!"
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_maddr
val print_maddr (m: maddr) (ptr_type: string) (reg_printer: (reg -> printer -> string)) (p: printer) : string
val print_maddr (m: maddr) (ptr_type: string) (reg_printer: (reg -> printer -> string)) (p: printer) : string
let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) )
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 88, "start_col": 0, "start_line": 79 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Vale.X64.Machine_s.maddr -> ptr_type: Prims.string -> reg_printer: (_: Vale.X64.Machine_s.reg -> _: Vale.X64.Print_s.printer -> Prims.string) -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.maddr", "Prims.string", "Vale.X64.Machine_s.reg", "Vale.X64.Print_s.printer", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__mem_prefix", "Prims.int", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Vale.X64.Print_s.__proj__Mkprinter__item__maddr", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Prims.string_of_int", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
false
true
false
let print_maddr (m: maddr) (ptr_type: string) (reg_printer: (reg -> printer -> string)) (p: printer) : string =
p.mem_prefix ptr_type ^ (match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset))
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.gcc_linux
val gcc_linux:printer
val gcc_linux:printer
let gcc_linux : printer = let footer () : string = ".section .note.GNU-stack,\"\",%progbits\n" in {gcc with footer}
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 379, "start_col": 0, "start_line": 377 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n') let print_header (p:printer) = print_string (p.header()) let print_proc (name:string) (code:code) (label:int) (p:printer) : FStar.All.ML int = let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label let print_footer (p:printer) = print_string (p.footer()) (* Concrete printers for MASM and GCC syntax *) let masm : printer = let reg_prefix unit = "" in let mem_prefix (ptr_type:string) = ptr_type ^ " ptr " in let maddr (base:string) (adj:option(string & string)) (offset:string) = match adj with | None -> "[" ^ base ^ " + " ^ offset ^ "]" | Some (scale, index) -> "[" ^ base ^ " + " ^ scale ^ " * " ^ index ^ " + " ^ offset ^ "]" in let const (n:int) = string_of_int n in let ins_name (name:string) (ops:list operand64) : string = name ^ " " in let op_order dst src = dst, src in let align() = "ALIGN" in let header() = ".code\n" in let footer() = "end\n" in let proc_name (name:string) = "ALIGN 16\n" ^ name ^ " proc\n" in let ret (name:string) = " ret\n" ^ name ^ " endp\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; op_order = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> true); } let gcc : printer = let reg_prefix unit = "%" in let mem_prefix (ptr_type:string) = "" in let maddr (base:string) (adj:option(string & string)) (offset:string) = match adj with | None -> offset ^ "(" ^ base ^ ")" | Some (scale, index) -> offset ^ " (" ^ base ^ ", " ^ scale ^ ", " ^ index ^ ")" in let const (n:int) = "$" ^ string_of_int n in let rec ins_name (name:string) (ops:list operand64) : string = match ops with | Nil -> name ^ " " | OMem _ :: _ -> name ^ "q " | _ :: tail -> ins_name name tail in let op_order dst src = src, dst in let align() = ".balign" in let header() = ".text\n" in let footer() = "\n" in let proc_name (name:string) = ".global " ^ name ^ "\n" ^ name ^ ":\n" in let ret (name:string) = " ret\n\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; op_order = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> false); }
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Print_s.printer
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Print_s.Mkprinter", "Vale.X64.Print_s.__proj__Mkprinter__item__print_reg_name", "Vale.X64.Print_s.gcc", "Vale.X64.Print_s.__proj__Mkprinter__item__print_reg32_name", "Vale.X64.Print_s.__proj__Mkprinter__item__print_small_reg_name", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__mem_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__maddr", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Vale.X64.Print_s.__proj__Mkprinter__item__ins_name", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order", "Vale.X64.Print_s.__proj__Mkprinter__item__align", "Vale.X64.Print_s.__proj__Mkprinter__item__header", "Vale.X64.Print_s.__proj__Mkprinter__item__proc_name", "Vale.X64.Print_s.__proj__Mkprinter__item__ret", "Vale.X64.Print_s.__proj__Mkprinter__item__sha256rnds2_explicit_xmm0", "Prims.unit", "Prims.string" ]
[]
false
false
false
true
false
let gcc_linux:printer =
let footer () : string = ".section .note.GNU-stack,\"\",%progbits\n" in { gcc with footer = footer }
false
Hacl.Impl.SecretBox.fst
Hacl.Impl.SecretBox.get_len0
val get_len0 (len: size_t) : Tot (r: size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)})
val get_len0 (len: size_t) : Tot (r: size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)})
let get_len0 (len:size_t) : Tot (r:size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) = if len <=. 32ul then len else 32ul
{ "file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 48, "start_col": 0, "start_line": 47 }
module Hacl.Impl.SecretBox open FStar.HyperStack.All open FStar.HyperStack open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Hacl.Salsa20 open Hacl.Poly1305_32 module ST = FStar.HyperStack.ST module Spec = Spec.SecretBox module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n))) let secretbox_init xkeys k n = let h0 = ST.get() in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1
{ "checked_file": "/", "dependencies": [ "Spec.SecretBox.fst.checked", "Spec.Salsa20.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Poly1305_32.fsti.checked", "Hacl.Salsa20.fst.checked", "Hacl.Poly1305_32.fsti.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.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SecretBox.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.SecretBox", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Salsa20", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "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", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> r: Lib.IntTypes.size_t {Lib.IntTypes.v r <= 32 /\ Lib.IntTypes.v r == Spec.SecretBox.get_len0 (Lib.IntTypes.v len)}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Lib.IntTypes.op_Less_Equals_Dot", "Lib.IntTypes.U32", "FStar.UInt32.__uint_to_t", "Prims.bool", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.max_size_t", "Spec.SecretBox.get_len0" ]
[]
false
false
false
false
false
let get_len0 (len: size_t) : Tot (r: size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) =
if len <=. 32ul then len else 32ul
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_shift_operand
val print_shift_operand (o: operand64) (p: printer) : string
val print_shift_operand (o: operand64) (p: printer) : string
let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl."
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 140, "start_col": 0, "start_line": 134 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.nat64", "Prims.op_LessThan", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Prims.bool", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.print_small_reg", "Vale.X64.Machine_s.__proj__OReg__item__r", "Vale.X64.Machine_s.operand" ]
[]
false
false
false
true
false
let print_shift_operand (o: operand64) (p: printer) : string =
match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl."
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_small_operand
val print_small_operand (o: operand64) (p: printer) : string
val print_small_operand (o: operand64) (p: printer) : string
let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl."
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 118, "start_col": 0, "start_line": 112 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.nat64", "Prims.op_LessThan", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Prims.bool", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.print_small_reg", "Vale.X64.Machine_s.operand" ]
[]
false
false
false
true
false
let print_small_operand (o: operand64) (p: printer) : string =
match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl."
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_mov128_op
val print_mov128_op (o: operand128) (p: printer) : string
val print_mov128_op (o: operand128) (p: printer) : string
let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 130, "start_col": 0, "start_line": 126 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand128 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand128", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.quad32", "Vale.X64.Machine_s.reg_xmm", "Vale.X64.Print_s.print_xmm", "Vale.X64.Machine_s.maddr", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Print_s.print_maddr", "Vale.X64.Print_s.print_reg_int", "Prims.string" ]
[]
false
false
false
true
false
let print_mov128_op (o: operand128) (p: printer) : string =
match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p
false
Pulse.Lib.SeqMatch.fsti
Pulse.Lib.SeqMatch.seq_map
val seq_map (#t1 #t2: Type) (f: (t1 -> t2)) (s: Seq.seq t1) : Tot (Seq.seq t2)
val seq_map (#t1 #t2: Type) (f: (t1 -> t2)) (s: Seq.seq t1) : Tot (Seq.seq t2)
let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) = Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.SeqMatch.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 337, "start_col": 0, "start_line": 336 }
(* Copyright 2023 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 Pulse.Lib.SeqMatch include Pulse.Lib.Pervasives open Pulse.Lib.Stick module Seq = FStar.Seq module SZ = FStar.SizeT (* `seq_list_match` describes how to match a sequence of low-level values (the low-level contents of an array) with a list of high-level values. `seq_list_match` is carefully designed to be usable within (mutually) recursive definitions of matching functions on the type of high-level values. *) val seq_list_match (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : Tot vprop val seq_list_match_nil_intro (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (pure (c `Seq.equal` Seq.empty /\ Nil? v)) (fun _ -> seq_list_match c v item_match) val seq_list_match_nil_elim (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (seq_list_match c v item_match ** pure ( c `Seq.equal` Seq.empty /\ Nil? v )) (fun _ -> emp) let list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)] = assert (List.Tot.hd (a :: q) << (a :: q)); assert (List.Tot.tl (a :: q) << (a :: q)) val seq_list_match_cons_intro (#t #t': Type) (a: t) (a' : t') (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << a' :: v }) -> vprop)) : stt_ghost unit (item_match a a' ** seq_list_match c v item_match) (fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match) val seq_list_match_cons_elim (#t #t': Type) (c: Seq.seq t) (v: list t' { Cons? v \/ Seq.length c > 0 }) (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost (squash (Cons? v /\ Seq.length c > 0)) (seq_list_match c v item_match) (fun _ -> item_match (Seq.head c) (List.Tot.hd v) ** seq_list_match (Seq.tail c) (List.Tot.tl v) item_match) // this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match val seq_list_match_weaken (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop)) (prf: ( (c': t) -> (v': t' { v' << v }) -> stt_ghost unit (item_match1 c' v') (fun _ -> item_match2 c' v') )) : stt_ghost unit (seq_list_match c v item_match1) (fun _ -> seq_list_match c v item_match2) (* `seq_seq_match` describes how to match a sequence of low-level values (the low-level contents of an array) with a sequence of high-level values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within (mutually) recursive definitions of matching functions on the type of high-level values, because no lemma ensures that `Seq.index s i << s` *) val seq_seq_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: Seq.seq t2) (i j: nat) : Tot vprop val seq_seq_match_length (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (s1: Seq.seq t1) (s2: Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p s1 s2 i j) (fun _ -> seq_seq_match p s1 s2 i j ** pure (i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))) val seq_seq_match_weaken (#t1 #t2: Type) (p p': t1 -> t2 -> vprop) (w: ((x1: t1) -> (x2: t2) -> stt_ghost unit (p x1 x2) (fun _ -> p' x1 x2) )) (c1 c1': Seq.seq t1) (c2 c2': Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p c1 c2 i j ** pure ( (i <= j /\ (i == j \/ ( j <= Seq.length c1 /\ j <= Seq.length c2 /\ j <= Seq.length c1' /\ j <= Seq.length c2' /\ Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\ Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j ))) )) (fun _ -> seq_seq_match p' c1' c2' i j) val seq_seq_match_weaken_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c1 c1': Seq.seq t1) (c2 c2': Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p c1 c2 i j ** pure ( (i <= j /\ (i == j \/ ( j <= Seq.length c1 /\ j <= Seq.length c2 /\ j <= Seq.length c1' /\ j <= Seq.length c2' /\ Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\ Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j ))) )) (fun _ -> seq_seq_match p c1' c2' i j ** (seq_seq_match p c1' c2' i j @==> seq_seq_match p c1 c2 i j) ) (* Going between `seq_list_match` and `seq_seq_match` *) val seq_seq_match_seq_list_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( (Seq.length c == List.Tot.length l) )) (fun _ -> seq_list_match c l p) val seq_list_match_seq_seq_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( Seq.length c == List.Tot.length l )) val seq_seq_match_seq_list_match_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( (Seq.length c == List.Tot.length l) )) (fun _ -> seq_list_match c l p ** (seq_list_match c l p @==> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))) val seq_list_match_seq_seq_match_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) @==> seq_list_match c l p) ** pure ( Seq.length c == List.Tot.length l )) val seq_list_match_length (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_list_match c l p ** pure ( Seq.length c == List.Tot.length l )) val seq_list_match_index (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (s1: Seq.seq t1) (s2: list t2) (i: nat) : stt_ghost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) (seq_list_match s1 s2 p ** pure ( (i < Seq.length s1 \/ i < List.Tot.length s2) )) (fun _ -> p (Seq.index s1 i) (List.Tot.index s2 i) ** (p (Seq.index s1 i) (List.Tot.index s2 i) @==> seq_list_match s1 s2 p) ) ```pulse ghost fn rec seq_list_match_append_intro (#t #t': Type0) // FIXME: universe polymorphism (item_match: (t -> t' -> vprop)) (c1: Seq.seq t) (l1: list t') (c2: Seq.seq t) (l2: list t') requires (seq_list_match c1 l1 item_match ** seq_list_match c2 l2 item_match) ensures (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) decreases l1 { seq_list_match_length item_match c1 l1; if (Nil? l1) { let prf : squash (c1 `Seq.equal` Seq.empty) = (); let prf2 = Seq.append_empty_l c2; seq_list_match_nil_elim c1 l1 item_match; rewrite (seq_list_match c2 l2 item_match) as (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) } else { let prf1 = seq_list_match_cons_elim c1 l1 item_match; seq_list_match_append_intro #t #t' item_match (Seq.tail c1) (List.Tot.tl l1) c2 l2; // FIXME: WHY WHY WHY do I need to provide those implicit arguments t, t'? seq_list_match_cons_intro (Seq.head c1) (List.Tot.hd l1) (Seq.tail c1 `Seq.append` c2) (List.Tot.tl l1 `List.Tot.append` l2) item_match; let prf2: squash (Seq.cons (Seq.head c1) (Seq.tail c1 `Seq.append` c2) `Seq.equal` (c1 `Seq.append` c2)) = (); rewrite (seq_list_match (Seq.cons (Seq.head c1) (Seq.tail c1 `Seq.append` c2)) (List.Tot.hd l1 :: (List.Tot.tl l1 `List.Tot.append` l2)) item_match) as (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) } } ``` ```pulse ghost fn rec seq_list_match_append_elim (#t #t': Type0) // FIXME: universe polymorphism (item_match: (t -> t' -> vprop)) (c1: Seq.seq t) (l1: list t') (c2: Seq.seq t) (l2: list t') requires (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match ** pure (Seq.length c1 == List.Tot.length l1 \/ Seq.length c2 == List.Tot.length l2)) ensures (seq_list_match c1 l1 item_match ** seq_list_match c2 l2 item_match ** pure ( Seq.length c1 == List.Tot.length l1 /\ Seq.length c2 == List.Tot.length l2 )) decreases l1 { seq_list_match_length item_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2); let prf_len_c = Seq.lemma_len_append c1 c2; let prf_len_l = List.Tot.append_length l1 l2; let prf : squash (Seq.length c1 == List.Tot.length l1 /\ Seq.length c2 == List.Tot.length l2) = (); if (Nil? l1) { let prf : squash (c1 `Seq.equal` Seq.empty) = (); let prf2 = Seq.append_empty_l c2; seq_list_match_nil_intro c1 l1 item_match; rewrite (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) as (seq_list_match c2 l2 item_match) } else { let prf1 = seq_list_match_cons_elim (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match; let prf_tl_c : squash (Seq.tail (c1 `Seq.append` c2) `Seq.equal` (Seq.tail c1 `Seq.append` c2)) = (); rewrite (seq_list_match (Seq.tail (c1 `Seq.append` c2)) (List.Tot.tl (l1 `List.Tot.append` l2)) item_match) as (seq_list_match (Seq.tail c1 `Seq.append` c2) (List.Tot.tl l1 `List.Tot.append` l2) item_match); seq_list_match_append_elim #t #t' item_match (Seq.tail c1) (List.Tot.tl l1) c2 l2; // FIXME: WHY WHY WHY do I need to provide those implicit arguments t, t'? seq_list_match_cons_intro (Seq.head (c1 `Seq.append` c2)) (List.Tot.hd (l1 `List.Tot.append` l2)) (Seq.tail c1) (List.Tot.tl l1) item_match; rewrite (seq_list_match (Seq.cons (Seq.head (c1 `Seq.append` c2)) (Seq.tail c1)) (List.Tot.hd (l1 `List.Tot.append` l2) :: List.Tot.tl l1) item_match) as (seq_list_match c1 l1 item_match) } } ``` (* Random array access Since `seq_list_match` is defined recursively on the list of high-level values, it is used naturally left-to-right. By contrast, in practice, an application may populate an array in a different order, or even out-of-order. `seq_seq_match` supports that scenario better, as we show below. *)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Stick.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Lib.SeqMatch.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "Pulse.Lib.Stick", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t1 -> t2) -> s: FStar.Seq.Base.seq t1 -> FStar.Seq.Base.seq t2
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "FStar.Seq.Base.init", "FStar.Seq.Base.length", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.index" ]
[]
false
false
false
true
false
let seq_map (#t1 #t2: Type) (f: (t1 -> t2)) (s: Seq.seq t1) : Tot (Seq.seq t2) =
Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.cmp_not
val cmp_not (o: ocmp) : ocmp
val cmp_not (o: ocmp) : ocmp
let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 149, "start_col": 0, "start_line": 142 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl."
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_Semantics_s.ocmp -> Vale.X64.Machine_Semantics_s.ocmp
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ocmp", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Vale.X64.Bytes_Code_s.ONe", "Vale.X64.Bytes_Code_s.OEq", "Vale.X64.Bytes_Code_s.OGt", "Vale.X64.Bytes_Code_s.OLt", "Vale.X64.Bytes_Code_s.OGe", "Vale.X64.Bytes_Code_s.OLe" ]
[]
false
false
false
true
false
let cmp_not (o: ocmp) : ocmp =
match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_operand32
val print_operand32 (o: operand64) (p: printer) : string
val print_operand32 (o: operand64) (p: printer) : string
let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 110, "start_col": 0, "start_line": 104 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: Vale.X64.Machine_s.operand64 -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.nat64", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.X64.Machine_s.pow2_32", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Prims.bool", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "Vale.X64.Machine_s.reg_64", "Vale.X64.Print_s.print_reg32", "Vale.X64.Machine_s.maddr", "Vale.Arch.HeapTypes_s.taint", "Vale.X64.Print_s.print_maddr", "Vale.X64.Print_s.print_reg_int" ]
[]
false
false
false
true
false
let print_operand32 (o: operand64) (p: printer) : string =
match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_instr
val print_instr (ip: instr_print) (p: printer) : string
val print_instr (ip: instr_print) (p: printer) : string
let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs)
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 199, "start_col": 0, "start_line": 158 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ip: Vale.X64.Instruction_s.instr_print -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Instruction_s.instr_print", "Vale.X64.Print_s.printer", "Prims.string", "Vale.X64.Instruction_s.instr_print_kind", "Prims.list", "Vale.X64.Instruction_s.instr_print_operand", "Prims.bool", "Prims.op_Hat", "Vale.X64.Print_s.print_pair", "Vale.X64.Machine_s.operand64", "Vale.X64.Print_s.print_small_operand", "Vale.X64.Print_s.print_operand32", "Vale.X64.Print_s.print_operand", "Vale.X64.Machine_s.operand128", "Vale.X64.Print_s.print_mov128_op", "Prims.int", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Vale.X64.Print_s.print_shift_operand", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Print_s.__proj__Mkprinter__item__ins_name", "Prims.Nil", "Prims.Cons", "Vale.X64.Print_s.__proj__Mkprinter__item__sha256rnds2_explicit_xmm0", "FStar.List.Tot.Base.op_At", "Vale.X64.Instruction_s.PXmm", "Vale.X64.Machine_s.OReg", "Vale.X64.Machine_s.quad32", "Vale.X64.Machine_s.reg_xmm" ]
[]
false
false
false
true
false
let print_instr (ip: instr_print) (p: printer) : string =
let Print name kind oprs = ip in let suffix, oprs = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs: list instr_print_operand) : list operand64 = match oprs with | [] -> [] | P8 o :: oprs -> o :: (get_operands oprs) | P16 o :: oprs -> o :: (get_operands oprs) | P32 o :: oprs -> o :: (get_operands oprs) | P64 o :: oprs -> o :: (get_operands oprs) | _ :: oprs -> get_operands oprs in let opcode, space = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po: instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs: list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o :: oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs)
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_ins
val print_ins (ins: ins) (p: printer) : string
val print_ins (ins: ins) (p: printer) : string
let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n)
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 98, "end_line": 240, "start_col": 0, "start_line": 201 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ins: Vale.X64.Machine_Semantics_s.ins -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Print_s.printer", "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.flag_havoc", "Vale.X64.Instruction_s.instr_t", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.InstrTypeRecord", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Instruction_s.instr_printer", "Vale.X64.Machine_s.operand64", "Vale.Arch.HeapTypes_s.taint", "Prims.op_Hat", "Vale.X64.Print_s.__proj__Mkprinter__item__ins_name", "Prims.Cons", "Prims.Nil", "Vale.X64.Print_s.print_operand", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.OReg", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.rRsp", "Vale.X64.Machine_s.OConst", "Prims.string", "Vale.X64.Instruction_s.instr_print", "Vale.X64.Print_s.print_instr", "Vale.X64.Machine_s.reg_xmm", "Vale.X64.Machine_s.operand128", "Vale.X64.Print_s.print_xmm", "Vale.X64.Print_s.print_mov128_op", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order", "Vale.X64.Print_s.print_operand32", "Vale.X64.Print_s.print_shift_operand", "Vale.X64.Print_s.print_pair" ]
[]
false
false
false
true
false
let print_ins (ins: ins) (p: printer) : string =
let print_pair (dst src: string) = print_pair dst src p in let print_op_pair (dst src: operand64) (print_dst print_src: (operand64 -> printer -> string)) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst src: operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst amount: operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst: reg_xmm) (src: operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst: reg_xmm) (src: operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst: operand64) (src: reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst src: reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2: reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1: reg_xmm) (src2: operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip: instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n)
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_code
val print_code (c: code) (n: int) (p: printer) : string & int
val print_code (c: code) (n: int) (p: printer) : string & int
let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n')
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 286, "start_col": 0, "start_line": 255 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.Machine_Semantics_s.code -> n: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string * Prims.int
Prims.Tot
[ "total" ]
[ "print_block", "print_code" ]
[ "Vale.X64.Machine_Semantics_s.code", "Prims.int", "Vale.X64.Print_s.printer", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "FStar.Pervasives.Native.Mktuple2", "Prims.string", "Prims.op_Hat", "Vale.X64.Print_s.print_ins", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Print_s.print_block", "Prims.string_of_int", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.print_code", "Prims.op_Addition", "Vale.X64.Print_s.print_cmp", "Vale.X64.Print_s.cmp_not", "Vale.X64.Print_s.__proj__Mkprinter__item__align" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec print_code (c: code) (n: int) (p: printer) : string & int =
match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let false_str, n' = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align () ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let body_str, n' = print_code body (n + 2) p in let label2 = p.align () ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n')
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.gcc
val gcc:printer
val gcc:printer
let gcc : printer = let reg_prefix unit = "%" in let mem_prefix (ptr_type:string) = "" in let maddr (base:string) (adj:option(string & string)) (offset:string) = match adj with | None -> offset ^ "(" ^ base ^ ")" | Some (scale, index) -> offset ^ " (" ^ base ^ ", " ^ scale ^ ", " ^ index ^ ")" in let const (n:int) = "$" ^ string_of_int n in let rec ins_name (name:string) (ops:list operand64) : string = match ops with | Nil -> name ^ " " | OMem _ :: _ -> name ^ "q " | _ :: tail -> ins_name name tail in let op_order dst src = src, dst in let align() = ".balign" in let header() = ".text\n" in let footer() = "\n" in let proc_name (name:string) = ".global " ^ name ^ "\n" ^ name ^ ":\n" in let ret (name:string) = " ret\n\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; op_order = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> false); }
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 374, "start_col": 0, "start_line": 337 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n') let print_header (p:printer) = print_string (p.header()) let print_proc (name:string) (code:code) (label:int) (p:printer) : FStar.All.ML int = let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label let print_footer (p:printer) = print_string (p.footer()) (* Concrete printers for MASM and GCC syntax *) let masm : printer = let reg_prefix unit = "" in let mem_prefix (ptr_type:string) = ptr_type ^ " ptr " in let maddr (base:string) (adj:option(string & string)) (offset:string) = match adj with | None -> "[" ^ base ^ " + " ^ offset ^ "]" | Some (scale, index) -> "[" ^ base ^ " + " ^ scale ^ " * " ^ index ^ " + " ^ offset ^ "]" in let const (n:int) = string_of_int n in let ins_name (name:string) (ops:list operand64) : string = name ^ " " in let op_order dst src = dst, src in let align() = "ALIGN" in let header() = ".code\n" in let footer() = "end\n" in let proc_name (name:string) = "ALIGN 16\n" ^ name ^ " proc\n" in let ret (name:string) = " ret\n" ^ name ^ " endp\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; op_order = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> true); }
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Print_s.printer
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Print_s.Mkprinter", "Vale.X64.Print_s.print_reg_name", "Vale.X64.Print_s.print_reg32_name", "Vale.X64.Print_s.print_small_reg_name", "Prims.unit", "Prims.bool", "Prims.string", "Prims.op_Hat", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_s.tmaddr", "Prims.int", "Prims.string_of_int", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let gcc:printer =
let reg_prefix unit = "%" in let mem_prefix (ptr_type: string) = "" in let maddr (base: string) (adj: option (string & string)) (offset: string) = match adj with | None -> offset ^ "(" ^ base ^ ")" | Some (scale, index) -> offset ^ " (" ^ base ^ ", " ^ scale ^ ", " ^ index ^ ")" in let const (n: int) = "$" ^ string_of_int n in let rec ins_name (name: string) (ops: list operand64) : string = match ops with | Nil -> name ^ " " | OMem _ :: _ -> name ^ "q " | _ :: tail -> ins_name name tail in let ( op_order ) dst src = src, dst in let align () = ".balign" in let header () = ".text\n" in let footer () = "\n" in let proc_name (name: string) = ".global " ^ name ^ "\n" ^ name ^ ":\n" in let ret (name: string) = " ret\n\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; ( op_order ) = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> false) }
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_cmp
val print_cmp (c: ocmp) (counter: int) (p: printer) : string
val print_cmp (c: ocmp) (counter: int) (p: printer) : string
let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 253, "start_col": 0, "start_line": 242 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.X64.Machine_Semantics_s.ocmp -> counter: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ocmp", "Prims.int", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order", "Vale.X64.Print_s.print_operand" ]
[]
false
false
false
true
false
let print_cmp (c: ocmp) (counter: int) (p: printer) : string =
let print_ops (o1 o2: operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne " ^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe " ^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae " ^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n"
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.masm
val masm:printer
val masm:printer
let masm : printer = let reg_prefix unit = "" in let mem_prefix (ptr_type:string) = ptr_type ^ " ptr " in let maddr (base:string) (adj:option(string & string)) (offset:string) = match adj with | None -> "[" ^ base ^ " + " ^ offset ^ "]" | Some (scale, index) -> "[" ^ base ^ " + " ^ scale ^ " * " ^ index ^ " + " ^ offset ^ "]" in let const (n:int) = string_of_int n in let ins_name (name:string) (ops:list operand64) : string = name ^ " " in let op_order dst src = dst, src in let align() = "ALIGN" in let header() = ".code\n" in let footer() = "end\n" in let proc_name (name:string) = "ALIGN 16\n" ^ name ^ " proc\n" in let ret (name:string) = " ret\n" ^ name ^ " endp\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; op_order = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> true); }
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 335, "start_col": 0, "start_line": 303 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n" let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n') let print_header (p:printer) = print_string (p.header()) let print_proc (name:string) (code:code) (label:int) (p:printer) : FStar.All.ML int = let proc = p.proc_name name in let code_str, final_label = print_code code label p in let ret = p.ret name in print_string (proc ^ code_str ^ ret); final_label let print_footer (p:printer) = print_string (p.footer())
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.X64.Print_s.printer
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Print_s.Mkprinter", "Vale.X64.Print_s.print_reg_name", "Vale.X64.Print_s.print_reg32_name", "Vale.X64.Print_s.print_small_reg_name", "Prims.unit", "Prims.bool", "Prims.string", "Prims.op_Hat", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "Vale.X64.Machine_s.operand64", "Prims.int", "Prims.string_of_int", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let masm:printer =
let reg_prefix unit = "" in let mem_prefix (ptr_type: string) = ptr_type ^ " ptr " in let maddr (base: string) (adj: option (string & string)) (offset: string) = match adj with | None -> "[" ^ base ^ " + " ^ offset ^ "]" | Some (scale, index) -> "[" ^ base ^ " + " ^ scale ^ " * " ^ index ^ " + " ^ offset ^ "]" in let const (n: int) = string_of_int n in let ins_name (name: string) (ops: list operand64) : string = name ^ " " in let ( op_order ) dst src = dst, src in let align () = "ALIGN" in let header () = ".code\n" in let footer () = "end\n" in let proc_name (name: string) = "ALIGN 16\n" ^ name ^ " proc\n" in let ret (name: string) = " ret\n" ^ name ^ " endp\n" in { print_reg_name = print_reg_name; print_reg32_name = print_reg32_name; print_small_reg_name = print_small_reg_name; reg_prefix = reg_prefix; mem_prefix = mem_prefix; maddr = maddr; const = const; ins_name = ins_name; ( op_order ) = op_order; align = align; header = header; footer = footer; proc_name = proc_name; ret = ret; sha256rnds2_explicit_xmm0 = (fun unit -> true) }
false
Vale.X64.Print_s.fst
Vale.X64.Print_s.print_block
val print_block (b: codes) (n: int) (p: printer) : string & int
val print_block (b: codes) (n: int) (p: printer) : string & int
let rec print_block (b:codes) (n:int) (p:printer) : string & int = match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let (head_str, n') = print_code head n p in let (rest, n'') = print_block tail n' p in (head_str ^ rest, n'') and print_code (c:code) (n:int) (p:printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (cmp_not cond) n1 p in let (true_str, n') = print_code true_code (n + 2) p in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = "L" ^ string_of_int n1 ^ ":\n" in let (false_str, n') = print_code false_code n' p in let label2 = "L" ^ string_of_int n2 ^ ":\n" in (cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n') | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " jmp L" ^ string_of_int n2 ^ "\n" in let label1 = p.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\n" in let (body_str, n') = print_code body (n + 2) p in let label2 = p.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\n" in let cmp = print_cmp cond n1 p in (jmp ^ label1 ^ body_str ^ label2 ^ cmp, n')
{ "file_name": "vale/specs/hardware/Vale.X64.Print_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 286, "start_col": 0, "start_line": 255 }
module Vale.X64.Print_s open FStar.Mul open FStar.List.Tot // Trusted code for producing assembly code open Vale.X64.Machine_s open Vale.X64.Instruction_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open FStar.IO noeq type printer = { print_reg_name: reg_64 -> string; print_reg32_name: reg_64 -> string; print_small_reg_name: reg_64 -> string; reg_prefix : unit -> string; mem_prefix : string -> string; maddr : string -> option (string & string) -> string -> string; const : int -> string; ins_name : string -> list operand64 -> string; op_order : string -> string -> string & string; align : unit -> string; header : unit -> string; footer : unit -> string; proc_name : string -> string; ret : string -> string; sha256rnds2_explicit_xmm0: unit -> bool; } let print_reg_name (r:reg_64) : string = match r with | 0 -> "rax" | 1 -> "rbx" | 2 -> "rcx" | 3 -> "rdx" | 4 -> "rsi" | 5 -> "rdi" | 6 -> "rbp" | 7 -> "rsp" | 8 -> "r8" | 9 -> "r9" | 10 -> "r10" | 11 -> "r11" | 12 -> "r12" | 13 -> "r13" | 14 -> "r14" | 15 -> "r15" let print_reg32_name (r:reg_64) : string = match r with | 0 -> "eax" | 1 -> "ebx" | 2 -> "ecx" | 3 -> "edx" | 4 -> "esi" | 5 -> "edi" | 6 -> "ebp" | 7 -> "esp" | _ -> print_reg_name r ^ "d" let print_small_reg_name (r:reg_64) : string = match r with | 0 -> "al" | 1 -> "bl" | 2 -> "cl" | 3 -> "dl" | _ -> " !!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_reg64 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg_name r let print_reg32 (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_reg32_name r let print_small_reg (r:reg_64) (p:printer) : string = p.reg_prefix() ^ p.print_small_reg_name r let print_maddr (m:maddr) (ptr_type:string) (reg_printer:reg -> printer -> string) (p:printer) : string = p.mem_prefix ptr_type ^ ( match m with | MConst n -> p.const n | MReg r offset -> p.maddr (reg_printer r p) None (string_of_int offset) | MIndex base scale index offset -> p.maddr (reg_printer base p) (Some (string_of_int scale, reg_printer index p)) (string_of_int offset) ) open FStar.UInt64 let print_reg_int (r:reg) (p:printer) : string = match r with | Reg 0 r -> print_reg64 r p | _ -> "!!! INVALID integer register !!!" let print_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg64 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "qword" print_reg_int p let print_operand32 (o:operand64) (p:printer) : string = match o with | OConst n -> if 0 <= n && n < pow2_32 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!" | OReg r -> print_reg32 r p | OMem (m, _) | OStack (m, _) -> print_maddr m "dword" print_reg_int p let print_small_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID constant: " ^ string_of_int n ^ " !!!!" | OReg r -> print_small_reg r p | _ -> "!!! INVALID small operand !!! Expected al, bl, cl, or dl." let print_imm8 (i:int) (p:printer) : string = p.const i let print_xmm (x:reg_xmm) (p:printer) : string = p.reg_prefix () ^ "xmm" ^ string_of_int x let print_mov128_op (o:operand128) (p:printer) : string = match o with | OConst _ -> "!!! INVALID xmm constants not allowed !!!" | OReg x -> print_xmm x p | OMem (m, _) | OStack (m, _) -> print_maddr m "xmmword" print_reg_int p assume val print_any: 'a -> string let print_shift_operand (o:operand64) (p:printer) : string = match o with | OConst n -> if n < 64 then p.const n else "!!! INVALID shift operand: " ^ string_of_int n ^ " is too large !!!" | OReg rRcx -> print_small_reg (OReg?.r o) p | _ -> "!!! INVALID shift operand !!! Expected constant or cl." let cmp_not(o:ocmp) : ocmp = match o with | OEq o1 o2 -> ONe o1 o2 | ONe o1 o2 -> OEq o1 o2 | OLe o1 o2 -> OGt o1 o2 | OGe o1 o2 -> OLt o1 o2 | OLt o1 o2 -> OGe o1 o2 | OGt o1 o2 -> OLe o1 o2 // Sanity check let _ = assert (forall o . o == cmp_not (cmp_not o)) let print_pair (dst src:string) (p:printer) : string = let first, second = p.op_order dst src in first ^ ", " ^ second let print_instr (ip:instr_print) (p:printer) : string = let Print name kind oprs = ip in let (suffix, oprs) = match kind with | POpcode -> (false, oprs) | PSuffix -> (true, oprs) | PrintPSha256rnds2 -> (false, (if p.sha256rnds2_explicit_xmm0 () then oprs @ [PXmm (OReg 0)] else oprs)) in let rec get_operands (oprs:list instr_print_operand) : list operand64 = match oprs with | [] -> [] | (P8 o)::oprs -> o::(get_operands oprs) | (P16 o)::oprs -> o::(get_operands oprs) | (P32 o)::oprs -> o::(get_operands oprs) | (P64 o)::oprs -> o::(get_operands oprs) | _::oprs -> get_operands oprs in let (opcode, space) = match suffix with | false -> (name, " ") | true -> (p.ins_name name (get_operands oprs), "") in let print_operand (po:instr_print_operand) : string = match po with | P8 o -> print_small_operand o p | P16 o -> "!!! UNSUPPORTED OPERAND !!!" | P32 o -> print_operand32 o p | P64 o -> print_operand o p | PXmm o -> print_mov128_op o p | PImm i -> p.const i | PShift o -> print_shift_operand o p in let rec print_operands (oprs:list instr_print_operand) : string = match oprs with | [] -> "" | [o] -> print_operand o | o::oprs -> print_pair (print_operand o) (print_operands oprs) p in match oprs with | [] -> " " ^ opcode | _ -> " " ^ opcode ^ space ^ (print_operands oprs) let print_ins (ins:ins) (p:printer) : string = let print_pair (dst src:string) = print_pair dst src p in let print_op_pair (dst:operand64) (src:operand64) (print_dst:operand64 -> printer -> string) (print_src:operand64 -> printer -> string) = print_pair (print_dst dst p) (print_src src p) in let print_ops (dst:operand64) (src:operand64) = print_op_pair dst src print_operand print_operand in let print_shift (dst:operand64) (amount:operand64) = print_op_pair dst amount print_operand print_shift_operand in let print_xmm_op (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand src p) in first ^ ", " ^ second in let print_xmm_op32 (dst:reg_xmm) (src:operand64) = let first, second = p.op_order (print_xmm dst p) (print_operand32 src p) in first ^ ", " ^ second in let print_op_xmm (dst:operand64) (src:reg_xmm) = let first, second = p.op_order (print_operand dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms (dst:reg_xmm) (src:reg_xmm) = let first, second = p.op_order (print_xmm dst p) (print_xmm src p) in first ^ ", " ^ second in let print_xmms_3 (dst src1 src2:reg_xmm) = print_pair (print_xmm dst p) (print_xmms src1 src2) in let print_vpxor (dst src1:reg_xmm) (src2:operand128) = print_pair (print_xmm dst p) (print_pair (print_xmm src1 p) (print_mov128_op src2 p)) in let print_instr (ip:instr_print) : string = print_instr ip p in match ins with | Instr (InstrTypeRecord i) oprs _ -> print_instr (instr_printer i oprs) | Push src _ -> p.ins_name " push" [src] ^ print_operand src p | Pop dst _ -> p.ins_name " pop" [dst] ^ print_operand dst p | Alloc n -> p.ins_name " sub" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) | Dealloc n -> p.ins_name " add" [OReg rRsp; OConst n] ^ print_ops (OReg rRsp) (OConst n) let print_cmp (c:ocmp) (counter:int) (p:printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.op_order (print_operand o1 p) (print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ "\n" | ONe o1 o2 -> print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ "\n" | OLe o1 o2 -> print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ "\n" | OGe o1 o2 -> print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ "\n" | OLt o1 o2 -> print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ "\n" | OGt o1 o2 -> print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ "\n"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_s.fst" }
[ { "abbrev": false, "full_module": "FStar.UInt64", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.X64.Machine_Semantics_s.codes -> n: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string * Prims.int
Prims.Tot
[ "total" ]
[ "print_block", "print_code" ]
[ "Vale.X64.Machine_Semantics_s.codes", "Prims.int", "Vale.X64.Print_s.printer", "FStar.Pervasives.Native.Mktuple2", "Prims.string", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Prims.nat", "Prims.eq2", "Vale.X64.Instruction_s.InstrTypeRecord", "Prims.Nil", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_Space", "Prims.list", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Print_s.print_block", "Vale.X64.Machine_Semantics_s.equals_instr", "Vale.X64.Instructions_s.ins_Ghost", "Prims.op_Hat", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.print_code" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec print_block (b: codes) (n: int) (p: printer) : string & int =
match b with | Nil -> ("", n) | Ins (Instr _ _ (AnnotateSpace _)) :: tail -> print_block tail n p | Ins (Instr _ _ (AnnotateGhost _)) :: tail -> print_block tail n p | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in (head_str ^ rest, n'')
false
Pulse.Lib.SeqMatch.fsti
Pulse.Lib.SeqMatch.item_match_option
val item_match_option (#t1 #t2: Type) (p: (t1 -> t2 -> vprop)) (x1: t1) (x2: option t2) : Tot vprop
val item_match_option (#t1 #t2: Type) (p: (t1 -> t2 -> vprop)) (x1: t1) (x2: option t2) : Tot vprop
let item_match_option (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (x1: t1) (x2: option t2) : Tot vprop = match x2 with | None -> emp | Some x2' -> p x1 x2'
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.SeqMatch.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 347, "start_col": 0, "start_line": 339 }
(* Copyright 2023 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 Pulse.Lib.SeqMatch include Pulse.Lib.Pervasives open Pulse.Lib.Stick module Seq = FStar.Seq module SZ = FStar.SizeT (* `seq_list_match` describes how to match a sequence of low-level values (the low-level contents of an array) with a list of high-level values. `seq_list_match` is carefully designed to be usable within (mutually) recursive definitions of matching functions on the type of high-level values. *) val seq_list_match (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : Tot vprop val seq_list_match_nil_intro (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (pure (c `Seq.equal` Seq.empty /\ Nil? v)) (fun _ -> seq_list_match c v item_match) val seq_list_match_nil_elim (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (seq_list_match c v item_match ** pure ( c `Seq.equal` Seq.empty /\ Nil? v )) (fun _ -> emp) let list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)] = assert (List.Tot.hd (a :: q) << (a :: q)); assert (List.Tot.tl (a :: q) << (a :: q)) val seq_list_match_cons_intro (#t #t': Type) (a: t) (a' : t') (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << a' :: v }) -> vprop)) : stt_ghost unit (item_match a a' ** seq_list_match c v item_match) (fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match) val seq_list_match_cons_elim (#t #t': Type) (c: Seq.seq t) (v: list t' { Cons? v \/ Seq.length c > 0 }) (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost (squash (Cons? v /\ Seq.length c > 0)) (seq_list_match c v item_match) (fun _ -> item_match (Seq.head c) (List.Tot.hd v) ** seq_list_match (Seq.tail c) (List.Tot.tl v) item_match) // this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match val seq_list_match_weaken (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop)) (prf: ( (c': t) -> (v': t' { v' << v }) -> stt_ghost unit (item_match1 c' v') (fun _ -> item_match2 c' v') )) : stt_ghost unit (seq_list_match c v item_match1) (fun _ -> seq_list_match c v item_match2) (* `seq_seq_match` describes how to match a sequence of low-level values (the low-level contents of an array) with a sequence of high-level values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within (mutually) recursive definitions of matching functions on the type of high-level values, because no lemma ensures that `Seq.index s i << s` *) val seq_seq_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: Seq.seq t2) (i j: nat) : Tot vprop val seq_seq_match_length (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (s1: Seq.seq t1) (s2: Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p s1 s2 i j) (fun _ -> seq_seq_match p s1 s2 i j ** pure (i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))) val seq_seq_match_weaken (#t1 #t2: Type) (p p': t1 -> t2 -> vprop) (w: ((x1: t1) -> (x2: t2) -> stt_ghost unit (p x1 x2) (fun _ -> p' x1 x2) )) (c1 c1': Seq.seq t1) (c2 c2': Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p c1 c2 i j ** pure ( (i <= j /\ (i == j \/ ( j <= Seq.length c1 /\ j <= Seq.length c2 /\ j <= Seq.length c1' /\ j <= Seq.length c2' /\ Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\ Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j ))) )) (fun _ -> seq_seq_match p' c1' c2' i j) val seq_seq_match_weaken_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c1 c1': Seq.seq t1) (c2 c2': Seq.seq t2) (i j: nat) : stt_ghost unit (seq_seq_match p c1 c2 i j ** pure ( (i <= j /\ (i == j \/ ( j <= Seq.length c1 /\ j <= Seq.length c2 /\ j <= Seq.length c1' /\ j <= Seq.length c2' /\ Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\ Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j ))) )) (fun _ -> seq_seq_match p c1' c2' i j ** (seq_seq_match p c1' c2' i j @==> seq_seq_match p c1 c2 i j) ) (* Going between `seq_list_match` and `seq_seq_match` *) val seq_seq_match_seq_list_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( (Seq.length c == List.Tot.length l) )) (fun _ -> seq_list_match c l p) val seq_list_match_seq_seq_match (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( Seq.length c == List.Tot.length l )) val seq_seq_match_seq_list_match_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** pure ( (Seq.length c == List.Tot.length l) )) (fun _ -> seq_list_match c l p ** (seq_list_match c l p @==> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))) val seq_list_match_seq_seq_match_with_implies (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) ** (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) @==> seq_list_match c l p) ** pure ( Seq.length c == List.Tot.length l )) val seq_list_match_length (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (c: Seq.seq t1) (l: list t2) : stt_ghost unit (seq_list_match c l p) (fun _ -> seq_list_match c l p ** pure ( Seq.length c == List.Tot.length l )) val seq_list_match_index (#t1 #t2: Type) (p: t1 -> t2 -> vprop) (s1: Seq.seq t1) (s2: list t2) (i: nat) : stt_ghost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) (seq_list_match s1 s2 p ** pure ( (i < Seq.length s1 \/ i < List.Tot.length s2) )) (fun _ -> p (Seq.index s1 i) (List.Tot.index s2 i) ** (p (Seq.index s1 i) (List.Tot.index s2 i) @==> seq_list_match s1 s2 p) ) ```pulse ghost fn rec seq_list_match_append_intro (#t #t': Type0) // FIXME: universe polymorphism (item_match: (t -> t' -> vprop)) (c1: Seq.seq t) (l1: list t') (c2: Seq.seq t) (l2: list t') requires (seq_list_match c1 l1 item_match ** seq_list_match c2 l2 item_match) ensures (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) decreases l1 { seq_list_match_length item_match c1 l1; if (Nil? l1) { let prf : squash (c1 `Seq.equal` Seq.empty) = (); let prf2 = Seq.append_empty_l c2; seq_list_match_nil_elim c1 l1 item_match; rewrite (seq_list_match c2 l2 item_match) as (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) } else { let prf1 = seq_list_match_cons_elim c1 l1 item_match; seq_list_match_append_intro #t #t' item_match (Seq.tail c1) (List.Tot.tl l1) c2 l2; // FIXME: WHY WHY WHY do I need to provide those implicit arguments t, t'? seq_list_match_cons_intro (Seq.head c1) (List.Tot.hd l1) (Seq.tail c1 `Seq.append` c2) (List.Tot.tl l1 `List.Tot.append` l2) item_match; let prf2: squash (Seq.cons (Seq.head c1) (Seq.tail c1 `Seq.append` c2) `Seq.equal` (c1 `Seq.append` c2)) = (); rewrite (seq_list_match (Seq.cons (Seq.head c1) (Seq.tail c1 `Seq.append` c2)) (List.Tot.hd l1 :: (List.Tot.tl l1 `List.Tot.append` l2)) item_match) as (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) } } ``` ```pulse ghost fn rec seq_list_match_append_elim (#t #t': Type0) // FIXME: universe polymorphism (item_match: (t -> t' -> vprop)) (c1: Seq.seq t) (l1: list t') (c2: Seq.seq t) (l2: list t') requires (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match ** pure (Seq.length c1 == List.Tot.length l1 \/ Seq.length c2 == List.Tot.length l2)) ensures (seq_list_match c1 l1 item_match ** seq_list_match c2 l2 item_match ** pure ( Seq.length c1 == List.Tot.length l1 /\ Seq.length c2 == List.Tot.length l2 )) decreases l1 { seq_list_match_length item_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2); let prf_len_c = Seq.lemma_len_append c1 c2; let prf_len_l = List.Tot.append_length l1 l2; let prf : squash (Seq.length c1 == List.Tot.length l1 /\ Seq.length c2 == List.Tot.length l2) = (); if (Nil? l1) { let prf : squash (c1 `Seq.equal` Seq.empty) = (); let prf2 = Seq.append_empty_l c2; seq_list_match_nil_intro c1 l1 item_match; rewrite (seq_list_match (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match) as (seq_list_match c2 l2 item_match) } else { let prf1 = seq_list_match_cons_elim (c1 `Seq.append` c2) (l1 `List.Tot.append` l2) item_match; let prf_tl_c : squash (Seq.tail (c1 `Seq.append` c2) `Seq.equal` (Seq.tail c1 `Seq.append` c2)) = (); rewrite (seq_list_match (Seq.tail (c1 `Seq.append` c2)) (List.Tot.tl (l1 `List.Tot.append` l2)) item_match) as (seq_list_match (Seq.tail c1 `Seq.append` c2) (List.Tot.tl l1 `List.Tot.append` l2) item_match); seq_list_match_append_elim #t #t' item_match (Seq.tail c1) (List.Tot.tl l1) c2 l2; // FIXME: WHY WHY WHY do I need to provide those implicit arguments t, t'? seq_list_match_cons_intro (Seq.head (c1 `Seq.append` c2)) (List.Tot.hd (l1 `List.Tot.append` l2)) (Seq.tail c1) (List.Tot.tl l1) item_match; rewrite (seq_list_match (Seq.cons (Seq.head (c1 `Seq.append` c2)) (Seq.tail c1)) (List.Tot.hd (l1 `List.Tot.append` l2) :: List.Tot.tl l1) item_match) as (seq_list_match c1 l1 item_match) } } ``` (* Random array access Since `seq_list_match` is defined recursively on the list of high-level values, it is used naturally left-to-right. By contrast, in practice, an application may populate an array in a different order, or even out-of-order. `seq_seq_match` supports that scenario better, as we show below. *) let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) = Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Stick.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Lib.SeqMatch.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "Pulse.Lib.Stick", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: t1 -> _: t2 -> Pulse.Lib.Core.vprop) -> x1: t1 -> x2: FStar.Pervasives.Native.option t2 -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Core.vprop", "FStar.Pervasives.Native.option", "Pulse.Lib.Core.emp" ]
[]
false
false
false
true
false
let item_match_option (#t1 #t2: Type) (p: (t1 -> t2 -> vprop)) (x1: t1) (x2: option t2) : Tot vprop =
match x2 with | None -> emp | Some x2' -> p x1 x2'
false
Pulse.Lib.SeqMatch.fsti
Pulse.Lib.SeqMatch.list_cons_precedes
val list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)]
val list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)]
let list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)] = assert (List.Tot.hd (a :: q) << (a :: q)); assert (List.Tot.tl (a :: q) << (a :: q))
{ "file_name": "share/steel/examples/pulse/lib/Pulse.Lib.SeqMatch.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 67, "start_col": 0, "start_line": 59 }
(* Copyright 2023 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 Pulse.Lib.SeqMatch include Pulse.Lib.Pervasives open Pulse.Lib.Stick module Seq = FStar.Seq module SZ = FStar.SizeT (* `seq_list_match` describes how to match a sequence of low-level values (the low-level contents of an array) with a list of high-level values. `seq_list_match` is carefully designed to be usable within (mutually) recursive definitions of matching functions on the type of high-level values. *) val seq_list_match (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : Tot vprop val seq_list_match_nil_intro (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (pure (c `Seq.equal` Seq.empty /\ Nil? v)) (fun _ -> seq_list_match c v item_match) val seq_list_match_nil_elim (#t #t': Type) (c: Seq.seq t) (v: list t') (item_match: (t -> (v': t' { v' << v }) -> vprop)) : stt_ghost unit (seq_list_match c v item_match ** pure ( c `Seq.equal` Seq.empty /\ Nil? v )) (fun _ -> emp)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Stick.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Lib.SeqMatch.fsti" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "Pulse.Lib.Stick", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: t -> q: Prims.list t -> FStar.Pervasives.Lemma (ensures a << a :: q /\ q << a :: q) [SMTPat (a :: q)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims._assert", "Prims.precedes", "FStar.List.Tot.Base.tl", "Prims.Cons", "Prims.unit", "FStar.List.Tot.Base.hd", "Prims.l_True", "Prims.squash", "Prims.l_and", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let list_cons_precedes (#t: Type) (a: t) (q: list t) : Lemma ((a << a :: q) /\ (q << a :: q)) [SMTPat (a :: q)] =
assert (List.Tot.hd (a :: q) << (a :: q)); assert (List.Tot.tl (a :: q) << (a :: q))
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr
val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 64, "start_col": 0, "start_line": 58 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_f", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[]
false
false
false
false
false
let bn_sqr #t #aLen a =
let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag
val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 41, "start_col": 0, "start_line": 39 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[]
false
false
false
false
false
let bn_sqr_diag #t #aLen a =
let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_f
val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 54, "start_col": 0, "start_line": 52 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> j: Prims.nat{j < aLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.limb", "Lib.Sequence.op_String_Assignment", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add", "Lib.Sequence.sub", "Lib.Sequence.op_String_Access" ]
[]
false
false
false
false
false
let bn_sqr_f #t #aLen a j acc =
let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[ j ] j acc in acc.[ j + j ] <- c
false
Hacl.Impl.SecretBox.fst
Hacl.Impl.SecretBox.secretbox_init
val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n)))
val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n)))
let secretbox_init xkeys k n = let h0 = ST.get() in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1
{ "file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 43, "start_col": 0, "start_line": 36 }
module Hacl.Impl.SecretBox open FStar.HyperStack.All open FStar.HyperStack open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Hacl.Salsa20 open Hacl.Poly1305_32 module ST = FStar.HyperStack.ST module Spec = Spec.SecretBox module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n)))
{ "checked_file": "/", "dependencies": [ "Spec.SecretBox.fst.checked", "Spec.Salsa20.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Poly1305_32.fsti.checked", "Hacl.Salsa20.fst.checked", "Hacl.Poly1305_32.fsti.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.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SecretBox.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.SecretBox", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Salsa20", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "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", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
xkeys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Hacl.Salsa20.salsa20_key_block0", "Prims.unit", "Hacl.Salsa20.hsalsa20", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let secretbox_init xkeys k n =
let h0 = ST.get () in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f
val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 30, "start_col": 0, "start_line": 26 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i < aLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) -> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen)
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.limb", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Prims.op_Multiply", "Lib.Sequence.index", "Prims.l_Forall", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "FStar.Mul.op_Star", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Base.mul_wide", "Lib.Sequence.op_String_Access" ]
[]
false
false
false
false
false
let bn_sqr_diag_f #t #aLen a i acc =
let hi, lo = mul_wide a.[ i ] a.[ i ] in let acc = acc.[ 2 * i ] <- lo in let acc = acc.[ 2 * i + 1 ] <- hi in acc
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_tail
val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0))
val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0))
let bn_sqr_tail #t #aLen a k = let _ = bn_sqr_inductive a k in ()
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 294, "start_col": 0, "start_line": 293 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i))) let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0 val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> k: Prims.nat{k <= aLen} -> FStar.Pervasives.Lemma (ensures (let acc0 = Lib.Sequence.create (aLen + aLen) (Lib.IntTypes.uint 0) in let acc = Lib.LoopCombinators.repeati k (Hacl.Spec.Bignum.Squaring.bn_sqr_f a) acc0 in forall (i: Prims.nat{k + k < i /\ i < aLen + aLen}). FStar.Seq.Base.index acc i == Lib.IntTypes.uint 0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Hacl.Spec.Bignum.Squaring.bn_sqr_inductive", "Prims.unit" ]
[]
true
false
true
false
false
let bn_sqr_tail #t #aLen a k =
let _ = bn_sqr_inductive a k in ()
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_lemma
val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1)))
val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1)))
let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in ()
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 155, "start_col": 0, "start_line": 154 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> k: Prims.nat{k <= aLen} -> FStar.Pervasives.Lemma (ensures (let acc0 = Lib.Sequence.create (aLen + aLen) (Lib.IntTypes.uint 0) in let acc = Lib.LoopCombinators.repeati k (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) acc0 in (forall (i: Prims.nat{i < k}). let _ = Hacl.Spec.Bignum.Base.mul_wide a.[ i ] a.[ i ] in (let FStar.Pervasives.Native.Mktuple2 #_ #_ hi lo = _ in FStar.Seq.Base.index acc (2 * i) == lo /\ FStar.Seq.Base.index acc (2 * i + 1) == hi) <: Type0) /\ (forall (i: Prims.nat{k <= i /\ i < aLen}). FStar.Seq.Base.index acc (2 * i) == FStar.Seq.Base.index acc0 (2 * i) /\ FStar.Seq.Base.index acc (2 * i + 1) == FStar.Seq.Base.index acc0 (2 * i + 1))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_inductive", "Prims.unit" ]
[]
true
false
true
false
false
let bn_sqr_diag_lemma #t #aLen a k =
let _ = bn_sqr_diag_inductive a k in ()
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma
val bn_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_sqr a == SM.bn_mul a a /\ bn_v (bn_sqr a) == bn_v a * bn_v a)
val bn_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_sqr a == SM.bn_mul a a /\ bn_v (bn_sqr a) == bn_v a * bn_v a)
let bn_sqr_lemma #t #aLen a = let res = bn_sqr a in bn_sqr_lemma_eval a; assert (bn_v res == bn_v a * bn_v a); let res' = SM.bn_mul a a in SM.bn_mul_lemma a a; assert (bn_v res' == bn_v a * bn_v a); bn_eval_inj (aLen + aLen) res res'; assert (bn_sqr a == SM.bn_mul a a)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 424, "start_col": 0, "start_line": 416 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i))) let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0 val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0)) let bn_sqr_tail #t #aLen a k = let _ = bn_sqr_inductive a k in () val square_of_sum: a:nat -> b:nat -> Lemma ((a + b) * (a + b) == a * a + 2 * a * b + b * b) let square_of_sum a b = () val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_eval_square #t #aLen a i = let e1 = eval_ aLen a (i - 1) in let p1 = pow2 (bits t * (i - 1)) in let p2 = pow2 (bits t * (i + i - 2)) in calc (==) { eval_ aLen a i * eval_ aLen a i; (==) { bn_eval_unfold_i a i } (e1 + v a.[i - 1] * p1) * (e1 + v a.[i - 1] * p1); (==) { square_of_sum e1 (v a.[i - 1] * p1) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + (v a.[i - 1] * p1) * (v a.[i - 1] * p1); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) p1 (v a.[i - 1] * p1); Math.Lemmas.paren_mul_right p1 p1 (v a.[i - 1]) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p1 * p1 * v a.[i - 1]); (==) { Math.Lemmas.pow2_plus (bits t * (i - 1)) (bits t * (i - 1)) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p2 * v a.[i - 1]); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v a.[i - 1]) p2 } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.paren_mul_right (2 * e1) (v a.[i - 1]) p1 } e1 * e1 + 2 * e1 * v a.[i - 1] * p1 + v a.[i - 1] * v a.[i - 1] * p2; } val bn_sqr_loop_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i) == eval_ aLen a i * eval_ aLen a i) #push-options "--z3rlimit 75" let rec bn_sqr_loop_lemma #t #aLen a i = let pbits = bits t in let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in if i = 0 then begin bn_eval0 acc; bn_eval0 tmp; bn_eval0 a end else begin let p1 = pow2 (pbits * (i + i - 1)) in let p2 = pow2 (pbits * (i + i - 2)) in let p3 = pow2 (pbits * (i - 1)) in let acc1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_f a) bn_zero in let tmp1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) bn_zero in unfold_repeati i (bn_sqr_f a) bn_zero (i - 1); assert (acc == bn_sqr_f a (i - 1) acc1); bn_sqr_f_lemma a (i - 1) acc1 (i + i - 1); assert (acc.[i + i - 1] == acc1.[i + i - 1]); bn_sqr_tail a (i - 1); assert (acc.[i + i - 1] == uint #t 0); calc (==) { 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i); (==) { bn_sqr_diag_loop_step a i } 2 * eval_ resLen acc (i + i) + eval_ resLen tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_unfold_i acc (i + i) } 2 * (eval_ resLen acc (i + i - 1) + v acc.[i + i - 1] * p1) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Classical.forall_intro (bn_sqr_f_lemma a (i - 1) acc1) } 2 * (eval_ resLen acc1 (i + i - 2) + eval_ aLen a (i - 1) * v a.[i - 1] * p3) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.distributivity_add_right 2 (eval_ resLen acc1 (i + i - 2)) (eval_ aLen a (i - 1) * v a.[i - 1] * p3) } 2 * eval_ resLen acc1 (i + i - 2) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_sqr_loop_lemma a (i - 1) } eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_square a i } eval_ aLen a i * eval_ aLen a i; }; () end #pop-options val bn_sqr_lemma_eval: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_v (bn_sqr a) == bn_v a * bn_v a) let bn_sqr_lemma_eval #t #aLen a = let pbits = bits t in let resLen = aLen + aLen in let res0 = create (aLen + aLen) (uint #t 0) in let res1 = repeati aLen (bn_sqr_f a) res0 in let c0, res2 = Hacl.Spec.Bignum.Addition.bn_add res1 res1 in Hacl.Spec.Bignum.Addition.bn_add_lemma res1 res1; let tmp = bn_sqr_diag a in let c1, res3 = Hacl.Spec.Bignum.Addition.bn_add res2 tmp in Hacl.Spec.Bignum.Addition.bn_add_lemma res2 tmp; assert ((v c0 + v c1) * pow2 (pbits * resLen) + bn_v res3 == 2 * bn_v res1 + bn_v tmp); bn_sqr_loop_lemma a aLen; assert (2 * bn_v res1 + bn_v tmp == bn_v a * bn_v a); bn_eval_bound a aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v a) (pow2 (pbits * aLen)); Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen); assert (bn_v a * bn_v a < pow2 (pbits * resLen)); bn_eval_bound res3 resLen; assert ((v c0 + v c1) = 0) val bn_sqr_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_sqr a == SM.bn_mul a a /\ bn_v (bn_sqr a) == bn_v a * bn_v a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Squaring.bn_sqr a == Hacl.Spec.Bignum.Multiplication.bn_mul a a /\ Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Squaring.bn_sqr a) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Squaring.bn_sqr", "Hacl.Spec.Bignum.Multiplication.bn_mul", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Multiplication.bn_mul_lemma", "Hacl.Spec.Bignum.Squaring.bn_sqr_lemma_eval" ]
[]
true
false
true
false
false
let bn_sqr_lemma #t #aLen a =
let res = bn_sqr a in bn_sqr_lemma_eval a; assert (bn_v res == bn_v a * bn_v a); let res' = SM.bn_mul a a in SM.bn_mul_lemma a a; assert (bn_v res' == bn_v a * bn_v a); bn_eval_inj (aLen + aLen) res res'; assert (bn_sqr a == SM.bn_mul a a)
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma_eval
val bn_sqr_lemma_eval: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_v (bn_sqr a) == bn_v a * bn_v a)
val bn_sqr_lemma_eval: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_v (bn_sqr a) == bn_v a * bn_v a)
let bn_sqr_lemma_eval #t #aLen a = let pbits = bits t in let resLen = aLen + aLen in let res0 = create (aLen + aLen) (uint #t 0) in let res1 = repeati aLen (bn_sqr_f a) res0 in let c0, res2 = Hacl.Spec.Bignum.Addition.bn_add res1 res1 in Hacl.Spec.Bignum.Addition.bn_add_lemma res1 res1; let tmp = bn_sqr_diag a in let c1, res3 = Hacl.Spec.Bignum.Addition.bn_add res2 tmp in Hacl.Spec.Bignum.Addition.bn_add_lemma res2 tmp; assert ((v c0 + v c1) * pow2 (pbits * resLen) + bn_v res3 == 2 * bn_v res1 + bn_v tmp); bn_sqr_loop_lemma a aLen; assert (2 * bn_v res1 + bn_v tmp == bn_v a * bn_v a); bn_eval_bound a aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v a) (pow2 (pbits * aLen)); Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen); assert (bn_v a * bn_v a < pow2 (pbits * resLen)); bn_eval_bound res3 resLen; assert ((v c0 + v c1) = 0)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 410, "start_col": 0, "start_line": 392 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i))) let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0 val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0)) let bn_sqr_tail #t #aLen a k = let _ = bn_sqr_inductive a k in () val square_of_sum: a:nat -> b:nat -> Lemma ((a + b) * (a + b) == a * a + 2 * a * b + b * b) let square_of_sum a b = () val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_eval_square #t #aLen a i = let e1 = eval_ aLen a (i - 1) in let p1 = pow2 (bits t * (i - 1)) in let p2 = pow2 (bits t * (i + i - 2)) in calc (==) { eval_ aLen a i * eval_ aLen a i; (==) { bn_eval_unfold_i a i } (e1 + v a.[i - 1] * p1) * (e1 + v a.[i - 1] * p1); (==) { square_of_sum e1 (v a.[i - 1] * p1) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + (v a.[i - 1] * p1) * (v a.[i - 1] * p1); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) p1 (v a.[i - 1] * p1); Math.Lemmas.paren_mul_right p1 p1 (v a.[i - 1]) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p1 * p1 * v a.[i - 1]); (==) { Math.Lemmas.pow2_plus (bits t * (i - 1)) (bits t * (i - 1)) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p2 * v a.[i - 1]); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v a.[i - 1]) p2 } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.paren_mul_right (2 * e1) (v a.[i - 1]) p1 } e1 * e1 + 2 * e1 * v a.[i - 1] * p1 + v a.[i - 1] * v a.[i - 1] * p2; } val bn_sqr_loop_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i) == eval_ aLen a i * eval_ aLen a i) #push-options "--z3rlimit 75" let rec bn_sqr_loop_lemma #t #aLen a i = let pbits = bits t in let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in if i = 0 then begin bn_eval0 acc; bn_eval0 tmp; bn_eval0 a end else begin let p1 = pow2 (pbits * (i + i - 1)) in let p2 = pow2 (pbits * (i + i - 2)) in let p3 = pow2 (pbits * (i - 1)) in let acc1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_f a) bn_zero in let tmp1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) bn_zero in unfold_repeati i (bn_sqr_f a) bn_zero (i - 1); assert (acc == bn_sqr_f a (i - 1) acc1); bn_sqr_f_lemma a (i - 1) acc1 (i + i - 1); assert (acc.[i + i - 1] == acc1.[i + i - 1]); bn_sqr_tail a (i - 1); assert (acc.[i + i - 1] == uint #t 0); calc (==) { 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i); (==) { bn_sqr_diag_loop_step a i } 2 * eval_ resLen acc (i + i) + eval_ resLen tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_unfold_i acc (i + i) } 2 * (eval_ resLen acc (i + i - 1) + v acc.[i + i - 1] * p1) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Classical.forall_intro (bn_sqr_f_lemma a (i - 1) acc1) } 2 * (eval_ resLen acc1 (i + i - 2) + eval_ aLen a (i - 1) * v a.[i - 1] * p3) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.distributivity_add_right 2 (eval_ resLen acc1 (i + i - 2)) (eval_ aLen a (i - 1) * v a.[i - 1] * p3) } 2 * eval_ resLen acc1 (i + i - 2) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_sqr_loop_lemma a (i - 1) } eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_square a i } eval_ aLen a i * eval_ aLen a i; }; () end #pop-options val bn_sqr_lemma_eval: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> Lemma (bn_v (bn_sqr a) == bn_v a * bn_v a)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Squaring.bn_sqr a) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "Prims._assert", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Prims.op_LessThan", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.pow2", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.lemma_mult_lt_sqr", "Prims.eq2", "Hacl.Spec.Bignum.Squaring.bn_sqr_loop_lemma", "Hacl.Spec.Bignum.Addition.bn_add_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_add", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_f", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_sqr_lemma_eval #t #aLen a =
let pbits = bits t in let resLen = aLen + aLen in let res0 = create (aLen + aLen) (uint #t 0) in let res1 = repeati aLen (bn_sqr_f a) res0 in let c0, res2 = Hacl.Spec.Bignum.Addition.bn_add res1 res1 in Hacl.Spec.Bignum.Addition.bn_add_lemma res1 res1; let tmp = bn_sqr_diag a in let c1, res3 = Hacl.Spec.Bignum.Addition.bn_add res2 tmp in Hacl.Spec.Bignum.Addition.bn_add_lemma res2 tmp; assert ((v c0 + v c1) * pow2 (pbits * resLen) + bn_v res3 == 2 * bn_v res1 + bn_v tmp); bn_sqr_loop_lemma a aLen; assert (2 * bn_v res1 + bn_v tmp == bn_v a * bn_v a); bn_eval_bound a aLen; Math.Lemmas.lemma_mult_lt_sqr (bn_v a) (bn_v a) (pow2 (pbits * aLen)); Math.Lemmas.pow2_plus (pbits * aLen) (pbits * aLen); assert (bn_v a * bn_v a < pow2 (pbits * resLen)); bn_eval_bound res3 resLen; assert ((v c0 + v c1) = 0)
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_inductive
val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1))))
val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1))))
let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 136, "start_col": 0, "start_line": 117 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> k: Prims.nat{k <= aLen} -> Prims.Pure (Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen))
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Lib.LoopCombinators.repeati_inductive", "FStar.Seq.Base.seq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "Prims.eq2", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "FStar.Mul.op_Star", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Base.mul_wide", "Lib.Sequence.op_String_Access", "Prims.unit", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f_lemma", "Lib.LoopCombinators.unfold_repeati", "Lib.LoopCombinators.eq_repeati0", "Lib.Sequence.lseq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[]
false
false
false
false
false
let bn_sqr_diag_inductive #t #aLen a k =
let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0: nat{i0 < i}). let hi, lo = mul_wide a.[ i0 ] a.[ i0 ] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0: nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_inductive
val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i)))
val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i)))
let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 281, "start_col": 0, "start_line": 267 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> k: Prims.nat{k <= aLen} -> Prims.Pure (Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen))
Prims.Pure
[]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Lib.LoopCombinators.repeati_inductive", "Prims.l_and", "Prims.eq2", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_f", "Prims.l_Forall", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Seq.Base.index", "Prims.unit", "Prims._assert", "FStar.Classical.forall_intro", "Prims.int", "Hacl.Spec.Bignum.Definitions.eval_", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Squaring.bn_sqr_f_lemma", "Lib.LoopCombinators.unfold_repeati", "Lib.LoopCombinators.eq_repeati0", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[]
false
false
false
false
false
let bn_sqr_inductive #t #aLen a k =
let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0: nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0: nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f_lemma
val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]))
val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]))
let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 96, "start_col": 0, "start_line": 80 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i < aLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Base.mul_wide a.[ i ] a.[ i ] in (let FStar.Pervasives.Native.Mktuple2 #_ #_ hi lo = _ in let res = Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a i acc in res.[ 2 * i ] == lo /\ res.[ 2 * i + 1 ] == hi /\ (forall (i0: Prims.nat{i0 < aLen /\ i0 <> i}). acc.[ 2 * i0 ] == res.[ 2 * i0 ] /\ acc.[ 2 * i0 + 1 ] == res.[ 2 * i0 + 1 ])) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.op_disEquality", "Prims.eq2", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "FStar.Mul.op_Star", "Lib.Sequence.op_String_Access", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.op_Multiply", "Lib.Sequence.index", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.int", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "Prims.l_Forall", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Lib.Sequence.op_String_Assignment", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Base.mul_wide" ]
[]
false
false
true
false
false
let bn_sqr_diag_f_lemma #t #aLen a i acc =
let hi, lo = mul_wide a.[ i ] a.[ i ] in let res1 = acc.[ 2 * i ] <- lo in let res = res1.[ 2 * i + 1 ] <- hi in let aux (i0: nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[ i0 ] == res.[ i0 ]) = () in let aux2 (i0: nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[ 2 * i0 ] == res.[ 2 * i0 ] /\ acc.[ 2 * i0 + 1 ] == res.[ 2 * i0 + 1 ]) = aux (2 * i0); aux (2 * i0 + 1); () in Classical.forall_intro aux2
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_f_lemma
val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i)
val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i)
let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 252, "start_col": 0, "start_line": 240 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> j: Lib.IntTypes.size_nat{j < aLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) -> i: Prims.nat{j + j < i /\ i < aLen + aLen} -> FStar.Pervasives.Lemma (ensures (let res = Hacl.Spec.Bignum.Squaring.bn_sqr_f a j acc in Hacl.Spec.Bignum.Definitions.eval_ (aLen + aLen) res (j + j + 1) == Hacl.Spec.Bignum.Definitions.eval_ (aLen + aLen) acc (j + j) + (Hacl.Spec.Bignum.Definitions.eval_ aLen a j * Lib.IntTypes.v a.[ j ]) * Prims.pow2 (Lib.IntTypes.bits t * j) /\ FStar.Seq.Base.index res i == FStar.Seq.Base.index acc i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_LessThan", "Prims.nat", "Prims.l_and", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Lib.Sequence.sub", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma", "Lib.Sequence.op_String_Access", "Prims._assert", "Prims.eq2", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "FStar.Seq.Base.upd", "Prims.l_Forall", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_disEquality", "Lib.Sequence.op_String_Assignment", "Lib.Sequence.update_sub", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place", "Prims.int" ]
[]
false
false
true
false
false
let bn_sqr_f_lemma #t #aLen a j acc i =
let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[ j ] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[ j + j ] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[ j ] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j
false
Benton2004.fst
Benton2004.exec_equiv_reified_trans
val exec_equiv_reified_trans (p p': sttype) (f1 f2 f3: reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3))
val exec_equiv_reified_trans (p p': sttype) (f1 f2 f3: reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3))
let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 74, "end_line": 419, "start_col": 0, "start_line": 379 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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" }
false
p: Benton2004.sttype -> p': Benton2004.sttype -> f1: Benton2004.reified_computation -> f2: Benton2004.reified_computation -> f3: Benton2004.reified_computation -> FStar.Pervasives.Lemma (requires Benton2004.is_per p' /\ Benton2004.interpolable p /\ Benton2004.exec_equiv_reified p p' f1 f2 /\ Benton2004.exec_equiv_reified p p' f2 f3) (ensures Benton2004.exec_equiv_reified p p' f1 f3)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.reified_computation", "FStar.Classical.forall_intro_3", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.nat", "Prims.l_imp", "Prims.l_and", "Benton2004.Aux.holds", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "FStar.Classical.move_requires", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.forall_intro", "Prims._assert", "Prims.op_Addition", "FStar.Pervasives.Native.tuple2", "Benton2004.interpolable_elim", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Benton2004.terminates_on", "Benton2004.is_per", "Benton2004.interpolable", "Benton2004.exec_equiv_reified" ]
[]
false
false
true
false
false
let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3: reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) =
let prf1 (s1 s3: heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel': nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y))
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_eq
val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k))
val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k))
let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k))
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 184, "start_col": 0, "start_line": 168 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> k: Prims.nat{k < aLen} -> FStar.Pervasives.Lemma (ensures (let acc0 = Lib.Sequence.create (aLen + aLen) (Lib.IntTypes.uint 0) in let acc1 = Lib.LoopCombinators.repeati k (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) acc0 in let acc2 = Lib.LoopCombinators.repeati (k + 1) (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) acc0 in Lib.Sequence.slice acc1 0 (2 * k) == Lib.Sequence.slice acc2 0 (2 * k)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_LessThan", "Lib.Sequence.eq_intro", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.Sequence.slice", "Prims.unit", "FStar.Classical.forall_intro", "Prims.eq2", "FStar.Seq.Base.index", "Prims.op_Multiply", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.l_and", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_lemma", "Prims.int", "Prims.op_Division", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[]
false
false
true
false
false
let bn_sqr_diag_eq #t #aLen a k =
let acc0 = create (aLen + aLen) (uint #t 0) in let acc1:lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2:lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i: nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k))
false
Hacl.Impl.SecretBox.fst
Hacl.Impl.SecretBox.secretbox_easy
val secretbox_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> c:lbuffer uint8 (mlen +! 16ul) -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ as_seq h1 c == Spec.secretbox_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 m))
val secretbox_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> c:lbuffer uint8 (mlen +! 16ul) -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ as_seq h1 c == Spec.secretbox_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 m))
let secretbox_easy mlen c k n m = let tag = sub c 0ul 16ul in let cip = sub c 16ul mlen in secretbox_detached mlen cip tag k n m; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 c) 16
{ "file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 246, "start_col": 0, "start_line": 241 }
module Hacl.Impl.SecretBox open FStar.HyperStack.All open FStar.HyperStack open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Hacl.Salsa20 open Hacl.Poly1305_32 module ST = FStar.HyperStack.ST module Spec = Spec.SecretBox module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n))) let secretbox_init xkeys k n = let h0 = ST.get() in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1 inline_for_extraction noextract let get_len0 (len:size_t) : Tot (r:size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) = if len <=. 32ul then len else 32ul #set-options "--z3rlimit 100" inline_for_extraction noextract val secretbox_detached_cipher: mlen:size_t -> c:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\ eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\ disjoint n m /\ disjoint n c /\ (let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n))) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ (let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h1 c == cipher)) let secretbox_detached_cipher mlen c k xkeys n m = let h0 = ST.get () in push_frame (); let n1 = sub n 16ul 8ul in let subkey = sub xkeys 0ul 32ul in let mkey = sub xkeys 32ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 m0; map2T 32ul block0 ( ^. ) block0 ekey0; let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let h1 = ST.get () in copy c0 (sub block0 0ul mlen0); let h2 = ST.get () in //assert (as_seq h2 c0 == LSeq.sub (as_seq h1 block0) 0 (v mlen0)); salsa20_encrypt mlen1 c1 m1 subkey n1 1ul; let h3 = ST.get () in //assert (as_seq h3 c1 == Spec.Salsa20.salsa20_encrypt_bytes (as_seq h2 subkey) (as_seq h2 n1) 1 (as_seq h2 m1)); FStar.Seq.Properties.lemma_split (as_seq h3 c) (v mlen0); //FStar.Seq.Properties.lemma_split (Seq.append (as_seq h2 c0) (as_seq h3 c1)) (v mlen0); assert (as_seq h3 c == Seq.append (as_seq h2 c0) (as_seq h3 c1)); assert ( let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h3 c == cipher); pop_frame () val secretbox_detached: mlen:size_t -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c |+| loc tag) h0 h1 /\ (as_seq h1 tag, as_seq h1 c) == Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m)) let secretbox_detached mlen c tag k n m = let h0 = ST.get () in push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in secretbox_detached_cipher mlen c k xkeys n m; Hacl.Streaming.Poly1305_32.mac tag c mlen mkey; let h1 = ST.get () in assert ( let (tag1, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in (as_seq h1 tag, as_seq h1 c) == (tag1, cipher)); pop_frame() inline_for_extraction noextract val secretbox_open_detached_plain: mlen:size_t -> m:lbuffer uint8 mlen -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c /\ disjoint xkeys m /\ disjoint xkeys c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let subkey = LSeq.sub (as_seq h0 xkeys) 0 32 in let ekey0 = LSeq.sub (as_seq h0 xkeys) 64 32 in let n1 = LSeq.sub (as_seq h0 n) 16 8 in let clen0 = Spec.get_len0 (v mlen) in let clen1 = v mlen - clen0 in let c0 = LSeq.sub (as_seq h0 c) 0 clen0 in let c1 = LSeq.sub (as_seq h0 c) clen0 clen1 in let block0 = LSeq.create 32 (u8 0) in let block0 = LSeq.update_sub block0 0 clen0 c0 in let block0 = LSeq.map2 (^.) block0 ekey0 in let m0 = LSeq.sub block0 0 clen0 in let m1 = Spec.Salsa20.salsa20_decrypt_bytes subkey n1 1 c1 in let msg = Seq.append m0 m1 in as_seq h1 m == msg)) let secretbox_open_detached_plain mlen m xkeys n c = push_frame (); let subkey = sub xkeys 0ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let n1 = sub n 16ul 8ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 c0; map2T 32ul block0 ( ^. ) block0 ekey0; let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in copy m0 (sub block0 0ul mlen0); salsa20_decrypt mlen1 m1 c1 subkey n1 1ul; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 m) (v mlen0); pop_frame () val secretbox_open_detached: mlen:size_t -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg)) let secretbox_open_detached mlen m k n c tag = push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in let tag' = create 16ul (u8 0) in Hacl.Streaming.Poly1305_32.mac tag' c mlen mkey; let res = if lbytes_eq tag tag' then ( secretbox_open_detached_plain mlen m xkeys n c; 0ul) else 0xfffffffful in pop_frame (); res val secretbox_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> c:lbuffer uint8 (mlen +! 16ul) -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ as_seq h1 c == Spec.secretbox_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 m))
{ "checked_file": "/", "dependencies": [ "Spec.SecretBox.fst.checked", "Spec.Salsa20.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Poly1305_32.fsti.checked", "Hacl.Salsa20.fst.checked", "Hacl.Poly1305_32.fsti.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.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SecretBox.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.SecretBox", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Salsa20", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "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", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mlen: Lib.IntTypes.size_t{Lib.IntTypes.v mlen + 16 <= Lib.IntTypes.max_size_t} -> c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (mlen +! 16ul) -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul -> m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Lib.IntTypes.op_Plus_Bang", "FStar.UInt32.__uint_to_t", "FStar.Seq.Properties.lemma_split", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.SecretBox.secretbox_detached", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.uint_to_t", "FStar.UInt32.t" ]
[]
false
true
false
false
false
let secretbox_easy mlen c k n m =
let tag = sub c 0ul 16ul in let cip = sub c 16ul mlen in secretbox_detached mlen cip tag k n m; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 c) 16
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_eval_square
val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
let bn_eval_square #t #aLen a i = let e1 = eval_ aLen a (i - 1) in let p1 = pow2 (bits t * (i - 1)) in let p2 = pow2 (bits t * (i + i - 2)) in calc (==) { eval_ aLen a i * eval_ aLen a i; (==) { bn_eval_unfold_i a i } (e1 + v a.[i - 1] * p1) * (e1 + v a.[i - 1] * p1); (==) { square_of_sum e1 (v a.[i - 1] * p1) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + (v a.[i - 1] * p1) * (v a.[i - 1] * p1); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) p1 (v a.[i - 1] * p1); Math.Lemmas.paren_mul_right p1 p1 (v a.[i - 1]) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p1 * p1 * v a.[i - 1]); (==) { Math.Lemmas.pow2_plus (bits t * (i - 1)) (bits t * (i - 1)) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p2 * v a.[i - 1]); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v a.[i - 1]) p2 } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.paren_mul_right (2 * e1) (v a.[i - 1]) p1 } e1 * e1 + 2 * e1 * v a.[i - 1] * p1 + v a.[i - 1] * v a.[i - 1] * p2; }
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 328, "start_col": 0, "start_line": 309 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i))) let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0 val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0)) let bn_sqr_tail #t #aLen a k = let _ = bn_sqr_inductive a k in () val square_of_sum: a:nat -> b:nat -> Lemma ((a + b) * (a + b) == a * a + 2 * a * b + b * b) let square_of_sum a b = () val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.pos{i <= aLen} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Hacl.Spec.Bignum.Definitions.eval_ aLen a i == Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) * Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) + ((2 * Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1)) * Lib.IntTypes.v a.[ i - 1 ]) * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) + (Lib.IntTypes.v a.[ i - 1 ] * Lib.IntTypes.v a.[ i - 1 ]) * Prims.pow2 (Lib.IntTypes.bits t * (i + i - 2)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.pos", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.eval_", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Prims.squash", "Hacl.Spec.Bignum.Squaring.square_of_sum", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.pow2_plus", "Lib.IntTypes.bits", "Prims.pow2", "Prims.nat" ]
[]
false
false
true
false
false
let bn_eval_square #t #aLen a i =
let e1 = eval_ aLen a (i - 1) in let p1 = pow2 (bits t * (i - 1)) in let p2 = pow2 (bits t * (i + i - 2)) in calc ( == ) { eval_ aLen a i * eval_ aLen a i; ( == ) { bn_eval_unfold_i a i } (e1 + v a.[ i - 1 ] * p1) * (e1 + v a.[ i - 1 ] * p1); ( == ) { square_of_sum e1 (v a.[ i - 1 ] * p1) } e1 * e1 + (2 * e1) * (v a.[ i - 1 ] * p1) + (v a.[ i - 1 ] * p1) * (v a.[ i - 1 ] * p1); ( == ) { (Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) p1 (v a.[ i - 1 ] * p1); Math.Lemmas.paren_mul_right p1 p1 (v a.[ i - 1 ])) } e1 * e1 + (2 * e1) * (v a.[ i - 1 ] * p1) + v a.[ i - 1 ] * ((p1 * p1) * v a.[ i - 1 ]); ( == ) { Math.Lemmas.pow2_plus (bits t * (i - 1)) (bits t * (i - 1)) } e1 * e1 + (2 * e1) * (v a.[ i - 1 ] * p1) + v a.[ i - 1 ] * (p2 * v a.[ i - 1 ]); ( == ) { Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) (v a.[ i - 1 ]) p2 } e1 * e1 + (2 * e1) * (v a.[ i - 1 ] * p1) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { Math.Lemmas.paren_mul_right (2 * e1) (v a.[ i - 1 ]) p1 } e1 * e1 + ((2 * e1) * v a.[ i - 1 ]) * p1 + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; }
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_diag_loop_step
val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2))))
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 100, "end_line": 225, "start_col": 0, "start_line": 198 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.pos{i <= aLen} -> FStar.Pervasives.Lemma (ensures (let acc0 = Lib.Sequence.create (aLen + aLen) (Lib.IntTypes.uint 0) in let acc1 = Lib.LoopCombinators.repeati i (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) acc0 in let acc2 = Lib.LoopCombinators.repeati (i - 1) (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) acc0 in Hacl.Spec.Bignum.Definitions.eval_ (aLen + aLen) acc1 (i + i) == Hacl.Spec.Bignum.Definitions.eval_ (aLen + aLen) acc2 (i + i - 2) + (Lib.IntTypes.v a.[ i - 1 ] * Lib.IntTypes.v a.[ i - 1 ]) * Prims.pow2 (Lib.IntTypes.bits t * (i + i - 2))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.pos", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pow2", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_eq", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.pow2_plus", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.distributivity_add_left", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_lemma", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f", "Lib.Sequence.lseq", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_sqr_diag_loop_step #t #aLen a i =
let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1:lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2:lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); calc ( == ) { v acc1.[ i + i - 2 ] * pow2 (pbits * (i + i - 2)) + v acc1.[ i + i - 1 ] * pow2 (pbits * (i + i - 1)); ( == ) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[ i + i - 2 ] * pow2 (pbits * (i + i - 2)) + v acc1.[ i + i - 1 ] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); ( == ) { Math.Lemmas.paren_mul_right (v acc1.[ i + i - 1 ]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[ i + i - 2 ] * pow2 (pbits * (i + i - 2)) + (v acc1.[ i + i - 1 ] * pow2 pbits) * pow2 (pbits * (i + i - 2)); ( == ) { Math.Lemmas.distributivity_add_left (v acc1.[ i + i - 2 ]) (v acc1.[ i + i - 1 ] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[ i + i - 2 ] + v acc1.[ i + i - 1 ] * pow2 pbits) * pow2 (pbits * (i + i - 2)); ( == ) { bn_sqr_diag_lemma a i } (v a.[ i - 1 ] * v a.[ i - 1 ]) * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * (pow2 (pbits * (i + i - 2))))
false
Hacl.Impl.SecretBox.fst
Hacl.Impl.SecretBox.secretbox_open_easy
val secretbox_open_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 (mlen +! 16ul) -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
val secretbox_open_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 (mlen +! 16ul) -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
let secretbox_open_easy mlen m k n c = let tag = sub c 0ul 16ul in let cip = sub c 16ul mlen in secretbox_open_detached mlen m k n cip tag
{ "file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 268, "start_col": 0, "start_line": 265 }
module Hacl.Impl.SecretBox open FStar.HyperStack.All open FStar.HyperStack open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Hacl.Salsa20 open Hacl.Poly1305_32 module ST = FStar.HyperStack.ST module Spec = Spec.SecretBox module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n))) let secretbox_init xkeys k n = let h0 = ST.get() in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1 inline_for_extraction noextract let get_len0 (len:size_t) : Tot (r:size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) = if len <=. 32ul then len else 32ul #set-options "--z3rlimit 100" inline_for_extraction noextract val secretbox_detached_cipher: mlen:size_t -> c:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\ eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\ disjoint n m /\ disjoint n c /\ (let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n))) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ (let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h1 c == cipher)) let secretbox_detached_cipher mlen c k xkeys n m = let h0 = ST.get () in push_frame (); let n1 = sub n 16ul 8ul in let subkey = sub xkeys 0ul 32ul in let mkey = sub xkeys 32ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 m0; map2T 32ul block0 ( ^. ) block0 ekey0; let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let h1 = ST.get () in copy c0 (sub block0 0ul mlen0); let h2 = ST.get () in //assert (as_seq h2 c0 == LSeq.sub (as_seq h1 block0) 0 (v mlen0)); salsa20_encrypt mlen1 c1 m1 subkey n1 1ul; let h3 = ST.get () in //assert (as_seq h3 c1 == Spec.Salsa20.salsa20_encrypt_bytes (as_seq h2 subkey) (as_seq h2 n1) 1 (as_seq h2 m1)); FStar.Seq.Properties.lemma_split (as_seq h3 c) (v mlen0); //FStar.Seq.Properties.lemma_split (Seq.append (as_seq h2 c0) (as_seq h3 c1)) (v mlen0); assert (as_seq h3 c == Seq.append (as_seq h2 c0) (as_seq h3 c1)); assert ( let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h3 c == cipher); pop_frame () val secretbox_detached: mlen:size_t -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c |+| loc tag) h0 h1 /\ (as_seq h1 tag, as_seq h1 c) == Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m)) let secretbox_detached mlen c tag k n m = let h0 = ST.get () in push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in secretbox_detached_cipher mlen c k xkeys n m; Hacl.Streaming.Poly1305_32.mac tag c mlen mkey; let h1 = ST.get () in assert ( let (tag1, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in (as_seq h1 tag, as_seq h1 c) == (tag1, cipher)); pop_frame() inline_for_extraction noextract val secretbox_open_detached_plain: mlen:size_t -> m:lbuffer uint8 mlen -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c /\ disjoint xkeys m /\ disjoint xkeys c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let subkey = LSeq.sub (as_seq h0 xkeys) 0 32 in let ekey0 = LSeq.sub (as_seq h0 xkeys) 64 32 in let n1 = LSeq.sub (as_seq h0 n) 16 8 in let clen0 = Spec.get_len0 (v mlen) in let clen1 = v mlen - clen0 in let c0 = LSeq.sub (as_seq h0 c) 0 clen0 in let c1 = LSeq.sub (as_seq h0 c) clen0 clen1 in let block0 = LSeq.create 32 (u8 0) in let block0 = LSeq.update_sub block0 0 clen0 c0 in let block0 = LSeq.map2 (^.) block0 ekey0 in let m0 = LSeq.sub block0 0 clen0 in let m1 = Spec.Salsa20.salsa20_decrypt_bytes subkey n1 1 c1 in let msg = Seq.append m0 m1 in as_seq h1 m == msg)) let secretbox_open_detached_plain mlen m xkeys n c = push_frame (); let subkey = sub xkeys 0ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let n1 = sub n 16ul 8ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 c0; map2T 32ul block0 ( ^. ) block0 ekey0; let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in copy m0 (sub block0 0ul mlen0); salsa20_decrypt mlen1 m1 c1 subkey n1 1ul; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 m) (v mlen0); pop_frame () val secretbox_open_detached: mlen:size_t -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg)) let secretbox_open_detached mlen m k n c tag = push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in let tag' = create 16ul (u8 0) in Hacl.Streaming.Poly1305_32.mac tag' c mlen mkey; let res = if lbytes_eq tag tag' then ( secretbox_open_detached_plain mlen m xkeys n c; 0ul) else 0xfffffffful in pop_frame (); res val secretbox_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> c:lbuffer uint8 (mlen +! 16ul) -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ as_seq h1 c == Spec.secretbox_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 m)) let secretbox_easy mlen c k n m = let tag = sub c 0ul 16ul in let cip = sub c 16ul mlen in secretbox_detached mlen cip tag k n m; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 c) 16 val secretbox_open_easy: mlen:size_t{v mlen + 16 <= max_size_t} -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 (mlen +! 16ul) -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_easy (as_seq h0 k) (as_seq h0 n) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
{ "checked_file": "/", "dependencies": [ "Spec.SecretBox.fst.checked", "Spec.Salsa20.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Poly1305_32.fsti.checked", "Hacl.Salsa20.fst.checked", "Hacl.Poly1305_32.fsti.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.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SecretBox.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.SecretBox", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Salsa20", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "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", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mlen: Lib.IntTypes.size_t{Lib.IntTypes.v mlen + 16 <= Lib.IntTypes.max_size_t} -> m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul -> c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 (mlen +! 16ul) -> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Plus_Bang", "Hacl.Impl.SecretBox.secretbox_open_detached", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.uint_to_t", "FStar.UInt32.t" ]
[]
false
true
false
false
false
let secretbox_open_easy mlen m k n c =
let tag = sub c 0ul 16ul in let cip = sub c 16ul mlen in secretbox_open_detached mlen m k n cip tag
false
Hacl.Impl.SHA2.Core.fst
Hacl.Impl.SHA2.Core.load_last8
val load_last8: #a:sha2_alg -> #m:m_spec{lanes a m = 8} -> load_last_t a m
val load_last8: #a:sha2_alg -> #m:m_spec{lanes a m = 8} -> load_last_t a m
let load_last8 #a #m totlen_buf len b fin last = let h0 = ST.get() in let (b0,(b1,(b2,(b3,(b4,(b5,(b6,b7))))))) = NTup.tup8 b in let last0 = sub last 0ul (2ul *! HD.block_len a) in let last1 = sub last (2ul *! HD.block_len a) (2ul *! HD.block_len a) in let last2 = sub last (4ul *! HD.block_len a) (2ul *! HD.block_len a) in let last3 = sub last (6ul *! HD.block_len a) (2ul *! HD.block_len a) in let last4 = sub last (8ul *! HD.block_len a) (2ul *! HD.block_len a) in let last5 = sub last (10ul *! HD.block_len a) (2ul *! HD.block_len a) in let last6 = sub last (12ul *! HD.block_len a) (2ul *! HD.block_len a) in let last7 = sub last (14ul *! HD.block_len a) (2ul *! HD.block_len a) in assert (internally_disjoint8 last0 last1 last2 last3 last4 last5 last6 last7); let h1 = ST.get() in assert (h0 == h1); LSeq.eq_intro (as_seq h1 last0) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last1) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last2) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last3) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last4) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last5) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last6) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last7) (LSeq.create (2 * block_length a) (u8 0)); let (l00,l01) = load_last_blocks #a totlen_buf len b0 fin last0 in let (l10,l11) = load_last_blocks #a totlen_buf len b1 fin last1 in let h2 = ST.get() in assert (modifies (loc last0 |+| loc last1) h0 h2); let (l20,l21) = load_last_blocks #a totlen_buf len b2 fin last2 in let (l30,l31) = load_last_blocks #a totlen_buf len b3 fin last3 in let h2 = ST.get() in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3) h0 h2); let (l40,l41) = load_last_blocks #a totlen_buf len b4 fin last4 in let (l50,l51) = load_last_blocks #a totlen_buf len b5 fin last5 in let h2 = ST.get() in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3 |+| loc last4 |+| loc last5) h0 h2); let (l60,l61) = load_last_blocks #a totlen_buf len b6 fin last6 in let (l70,l71) = load_last_blocks #a totlen_buf len b7 fin last7 in let h3 = ST.get() in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3 |+| loc last4 |+| loc last5 |+| loc last6 |+| loc last7) h0 h3); assert (modifies (loc last) h0 h3); let mb0:multibuf (lanes a m) (HD.block_len a) = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in let mb1:multibuf (lanes a m) (HD.block_len a) = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in ntup8_lemma #_ #8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))); ntup8_lemma #_ #8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))); assert (live_multi h3 mb0); assert (live_multi h3 mb1); NTup.eq_intro (as_seq_multi h3 mb0) (ntup8 (as_seq h3 l00, (as_seq h3 l10, (as_seq h3 l20, (as_seq h3 l30, (as_seq h3 l40, (as_seq h3 l50, (as_seq h3 l60, (as_seq h3 l70))))))))); NTup.eq_intro (as_seq_multi h3 mb1) (ntup8 (as_seq h3 l01, (as_seq h3 l11, (as_seq h3 l21, (as_seq h3 l31, (as_seq h3 l41, (as_seq h3 l51, (as_seq h3 l61, (as_seq h3 l71))))))))); assert ((as_seq_multi h3 mb0, as_seq_multi h3 mb1) == SpecVec.load_last8 #a #m (as_seq h0 totlen_buf) (v fin) (v len) (as_seq_multi h0 b)); reveal_opaque (`%SpecVec.load_last) (SpecVec.load_last #a #m); (mb0, mb1)
{ "file_name": "code/sha2-mb/Hacl.Impl.SHA2.Core.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 533, "start_col": 0, "start_line": 481 }
module Hacl.Impl.SHA2.Core open FStar.Mul open FStar.HyperStack open FStar.HyperStack.All open Lib.IntTypes open Lib.NTuple open Lib.Buffer open Lib.IntVector open Lib.MultiBuffer open Spec.Hash.Definitions //open Hacl.Hash.Definitions // <- defines as_seq which clashes with Lib.Buffer.as_seq open Hacl.Spec.SHA2.Vec module ST = FStar.HyperStack.ST module NTup = Lib.NTuple module SpecVec = Hacl.Spec.SHA2.Vec module VecTranspose = Lib.IntVector.Transpose module LSeq = Lib.Sequence module HD = Hacl.Hash.Definitions (* Force ordering in dependency analysis so that monomorphizations are inserted into the Types module first. *) let _ = Hacl.Impl.SHA2.Types.uint8_8p #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" unfold let state_t (a:sha2_alg) (m:m_spec) = lbuffer (element_t a m) 8ul unfold let block_t (a:sha2_alg) = lbuffer uint8 (HD.block_len a) inline_for_extraction noextract let ws_t (a:sha2_alg) (m:m_spec) = lbuffer (element_t a m) 16ul inline_for_extraction noextract val set_wsi: #a:sha2_alg -> #m:m_spec -> ws:ws_t a m -> i:size_t{v i < 16} -> b:lbuffer uint8 (HD.block_len a) -> bi:size_t{v bi < 16 / (lanes a m)} -> Stack unit (requires fun h -> live h b /\ live h ws /\ disjoint b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == LSeq.upd (as_seq h0 ws) (v i) (SpecVec.load_elementi #a #m (as_seq h0 b) (v bi))) let set_wsi #a #m ws i b bi = [@inline_let] let l = lanes a m in ws.(i) <- vec_load_be (word_t a) l (sub b (bi *! size l *! HD.word_len a) (size l *! HD.word_len a)) noextract let load_blocks_spec1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (b:multiblock_spec a m) : ws_spec a m = let b = b.(|0|) in let ws0 = SpecVec.load_elementi b 0 in let ws1 = SpecVec.load_elementi b 1 in let ws2 = SpecVec.load_elementi b 2 in let ws3 = SpecVec.load_elementi b 3 in let ws4 = SpecVec.load_elementi b 4 in let ws5 = SpecVec.load_elementi b 5 in let ws6 = SpecVec.load_elementi b 6 in let ws7 = SpecVec.load_elementi b 7 in let ws8 = SpecVec.load_elementi b 8 in let ws9 = SpecVec.load_elementi b 9 in let ws10 = SpecVec.load_elementi b 10 in let ws11 = SpecVec.load_elementi b 11 in let ws12 = SpecVec.load_elementi b 12 in let ws13 = SpecVec.load_elementi b 13 in let ws14 = SpecVec.load_elementi b 14 in let ws15 = SpecVec.load_elementi b 15 in LSeq.create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 noextract let load_blocks_spec1_lemma (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (b:multiblock_spec a m) : Lemma (SpecVec.load_blocks b == load_blocks_spec1 b) = LSeq.eq_intro (SpecVec.load_blocks b) (load_blocks_spec1 b) #push-options "--z3rlimit 100" inline_for_extraction noextract val load_blocks1: #a:sha2_alg -> #m:m_spec{lanes a m == 1} -> b:multibuf (lanes a m) (HD.block_len a) -> ws:ws_t a m -> Stack unit (requires fun h -> live_multi h b /\ live h ws /\ disjoint_multi b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 b)) let load_blocks1 #a #m ib ws = let h0 = ST.get() in let b = ib.(|0|) in set_wsi ws 0ul b 0ul; set_wsi ws 1ul b 1ul; set_wsi ws 2ul b 2ul; set_wsi ws 3ul b 3ul; set_wsi ws 4ul b 4ul; set_wsi ws 5ul b 5ul; set_wsi ws 6ul b 6ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); set_wsi ws 7ul b 7ul; set_wsi ws 8ul b 8ul; set_wsi ws 9ul b 9ul; set_wsi ws 10ul b 10ul; set_wsi ws 11ul b 11ul; set_wsi ws 12ul b 12ul; set_wsi ws 13ul b 13ul; set_wsi ws 14ul b 14ul; set_wsi ws 15ul b 15ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); LSeq.eq_intro (as_seq h1 ws) (load_blocks_spec1 (as_seq_multi h0 ib)); load_blocks_spec1_lemma #a #m (as_seq_multi h0 ib); assert (as_seq h1 ws == load_blocks_spec1 (as_seq_multi h0 ib)); assert (as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 ib)) #pop-options noextract let load_blocks_spec4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (b:multiblock_spec a m) : ws_spec a m = let b0 = b.(|0|) in let b1 = b.(|1|) in let b2 = b.(|2|) in let b3 = b.(|3|) in let ws0 = SpecVec.load_elementi b0 0 in let ws1 = SpecVec.load_elementi b1 0 in let ws2 = SpecVec.load_elementi b2 0 in let ws3 = SpecVec.load_elementi b3 0 in let ws4 = SpecVec.load_elementi b0 1 in let ws5 = SpecVec.load_elementi b1 1 in let ws6 = SpecVec.load_elementi b2 1 in let ws7 = SpecVec.load_elementi b3 1 in let ws8 = SpecVec.load_elementi b0 2 in let ws9 = SpecVec.load_elementi b1 2 in let ws10 = SpecVec.load_elementi b2 2 in let ws11 = SpecVec.load_elementi b3 2 in let ws12 = SpecVec.load_elementi b0 3 in let ws13 = SpecVec.load_elementi b1 3 in let ws14 = SpecVec.load_elementi b2 3 in let ws15 = SpecVec.load_elementi b3 3 in LSeq.create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 noextract let load_blocks_spec4_lemma (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (b:multiblock_spec a m) : Lemma (SpecVec.load_blocks b == load_blocks_spec4 b) = LSeq.eq_intro (SpecVec.load_blocks b) (load_blocks_spec4 b) inline_for_extraction noextract val load_blocks4: #a:sha2_alg -> #m:m_spec{lanes a m == 4} -> b:multibuf (lanes a m) (HD.block_len a) -> ws:ws_t a m -> Stack unit (requires fun h -> live_multi h b /\ live h ws /\ disjoint_multi b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 b)) #push-options "--z3rlimit 150" let load_blocks4 #a #m ib ws = let h0 = ST.get() in let (b0,(b1,(b2,b3))) = NTup.tup4 ib in set_wsi ws 0ul b0 0ul; set_wsi ws 1ul b1 0ul; set_wsi ws 2ul b2 0ul; set_wsi ws 3ul b3 0ul; set_wsi ws 4ul b0 1ul; set_wsi ws 5ul b1 1ul; set_wsi ws 6ul b2 1ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); set_wsi ws 7ul b3 1ul; set_wsi ws 8ul b0 2ul; set_wsi ws 9ul b1 2ul; set_wsi ws 10ul b2 2ul; set_wsi ws 11ul b3 2ul; set_wsi ws 12ul b0 3ul; set_wsi ws 13ul b1 3ul; set_wsi ws 14ul b2 3ul; set_wsi ws 15ul b3 3ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); LSeq.eq_intro (as_seq h1 ws) (load_blocks_spec4 (as_seq_multi h0 ib)); load_blocks_spec4_lemma #a #m (as_seq_multi h0 ib); assert (as_seq h1 ws == load_blocks_spec4 (as_seq_multi h0 ib)); assert (as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 ib)); () #pop-options noextract let load_blocks_spec8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (b:multiblock_spec a m) : ws_spec a m = let b0 = b.(|0|) in let b1 = b.(|1|) in let b2 = b.(|2|) in let b3 = b.(|3|) in let b4 = b.(|4|) in let b5 = b.(|5|) in let b6 = b.(|6|) in let b7 = b.(|7|) in let ws0 = SpecVec.load_elementi b0 0 in let ws1 = SpecVec.load_elementi b1 0 in let ws2 = SpecVec.load_elementi b2 0 in let ws3 = SpecVec.load_elementi b3 0 in let ws4 = SpecVec.load_elementi b4 0 in let ws5 = SpecVec.load_elementi b5 0 in let ws6 = SpecVec.load_elementi b6 0 in let ws7 = SpecVec.load_elementi b7 0 in let ws8 = SpecVec.load_elementi b0 1 in let ws9 = SpecVec.load_elementi b1 1 in let ws10 = SpecVec.load_elementi b2 1 in let ws11 = SpecVec.load_elementi b3 1 in let ws12 = SpecVec.load_elementi b4 1 in let ws13 = SpecVec.load_elementi b5 1 in let ws14 = SpecVec.load_elementi b6 1 in let ws15 = SpecVec.load_elementi b7 1 in LSeq.create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 noextract let load_blocks_spec8_lemma (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (b:multiblock_spec a m) : Lemma (SpecVec.load_blocks b == load_blocks_spec8 b) = LSeq.eq_intro (SpecVec.load_blocks b) (load_blocks_spec8 b) inline_for_extraction noextract val load_blocks8: #a:sha2_alg -> #m:m_spec{lanes a m == 8} -> b:multibuf (lanes a m) (HD.block_len a) -> ws:ws_t a m -> Stack unit (requires fun h -> live_multi h b /\ live h ws /\ disjoint_multi b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 b)) #push-options "--z3rlimit 150" let load_blocks8 #a #m ib ws = let h0 = ST.get() in let (b0,(b1,(b2,(b3,(b4,(b5,(b6,b7))))))) = NTup.tup8 ib in set_wsi ws 0ul b0 0ul; set_wsi ws 1ul b1 0ul; set_wsi ws 2ul b2 0ul; set_wsi ws 3ul b3 0ul; set_wsi ws 4ul b4 0ul; set_wsi ws 5ul b5 0ul; set_wsi ws 6ul b6 0ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); set_wsi ws 7ul b7 0ul; set_wsi ws 8ul b0 1ul; set_wsi ws 9ul b1 1ul; set_wsi ws 10ul b2 1ul; set_wsi ws 11ul b3 1ul; set_wsi ws 12ul b4 1ul; set_wsi ws 13ul b5 1ul; set_wsi ws 14ul b6 1ul; set_wsi ws 15ul b7 1ul; let h1 = ST.get() in assert (modifies (loc ws) h0 h1); LSeq.eq_intro (as_seq h1 ws) (load_blocks_spec8 (as_seq_multi h0 ib)); load_blocks_spec8_lemma #a #m (as_seq_multi h0 ib); assert (as_seq h1 ws == load_blocks_spec8 (as_seq_multi h0 ib)); assert (as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 ib)); () #pop-options inline_for_extraction noextract val load_blocks: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multibuf (lanes a m) (HD.block_len a) -> ws:ws_t a m -> Stack unit (requires fun h -> live_multi h b /\ live h ws /\ disjoint_multi b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.load_blocks (as_seq_multi h0 b)) let load_blocks #a #m b ws = match lanes a m with | 1 -> load_blocks1 b ws | 4 -> load_blocks4 b ws | 8 -> load_blocks8 b ws inline_for_extraction noextract val transpose_ws4: #a:sha2_alg -> #m:m_spec{lanes a m == 4} -> ws:ws_t a m -> Stack unit (requires fun h -> live h ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.transpose_ws (as_seq h0 ws)) let transpose_ws4 #a #m ws = let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.(0ul),ws.(1ul),ws.(2ul),ws.(3ul)) in let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.(4ul),ws.(5ul),ws.(6ul),ws.(7ul)) in let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.(8ul),ws.(9ul),ws.(10ul),ws.(11ul)) in let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.(12ul),ws.(13ul),ws.(14ul),ws.(15ul)) in create16 ws ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 inline_for_extraction noextract val transpose_ws8: #a:sha2_alg -> #m:m_spec{lanes a m == 8} -> ws:ws_t a m -> Stack unit (requires fun h -> live h ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.transpose_ws (as_seq h0 ws)) let transpose_ws8 #a #m ws = let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.(0ul),ws.(1ul),ws.(2ul),ws.(3ul),ws.(4ul),ws.(5ul),ws.(6ul),ws.(7ul)) in let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.(8ul),ws.(9ul),ws.(10ul),ws.(11ul),ws.(12ul),ws.(13ul),ws.(14ul),ws.(15ul)) in create16 ws ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 inline_for_extraction noextract val transpose_ws: #a:sha2_alg -> #m:m_spec{is_supported a m} -> ws:ws_t a m -> Stack unit (requires fun h -> live h ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.transpose_ws (as_seq h0 ws)) let transpose_ws #a #m ws = match lanes a m with | 1 -> () | 4 -> transpose_ws4 ws | 8 -> transpose_ws8 ws inline_for_extraction noextract val load_ws: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multibuf (lanes a m) (HD.block_len a) -> ws:ws_t a m -> Stack unit (requires fun h -> live_multi h b /\ live h ws /\ disjoint_multi b ws) (ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\ as_seq h1 ws == SpecVec.load_ws #a #m (as_seq_multi h0 b)) let load_ws #a #m b ws = load_blocks b ws; transpose_ws ws inline_for_extraction noextract let padded_blocks (a:sha2_alg) (len:size_t{v len <= block_length a}) : n:size_t{v n == SpecVec.padded_blocks a (v len)} = if (len +! len_len a +! 1ul <=. HD.block_len a) then 1ul else 2ul inline_for_extraction noextract val load_last_blocks: #a:sha2_alg -> totlen_buf:lbuffer uint8 (len_len a) -> len:size_t{v len <= block_length a} -> b:lbuffer uint8 len -> fin:size_t{v fin == block_length a \/ v fin == 2 * block_length a} -> last:lbuffer uint8 (2ul *! HD.block_len a) -> Stack (lbuffer uint8 (HD.block_len a) & lbuffer uint8 (HD.block_len a)) (requires fun h -> live h totlen_buf /\ live h b /\ live h last /\ disjoint b last /\ disjoint last totlen_buf /\ as_seq h last == LSeq.create (2 * block_length a) (u8 0)) (ensures (fun h0 (l0,l1) h1 -> modifies (loc last) h0 h1 /\ live h1 l0 /\ live h1 l1 /\ (forall a l (r:lbuffer a l). disjoint last r ==> (disjoint l0 r /\ disjoint l1 r)) /\ (as_seq h1 l0, as_seq h1 l1) == SpecVec.load_last_blocks #a (as_seq h0 totlen_buf) (v fin) (v len) (as_seq h0 b))) #push-options "--z3rlimit 200" let load_last_blocks #a totlen_buf len b fin last = let h0 = ST.get() in update_sub last 0ul len b; last.(len) <- u8 0x80; update_sub last (fin -. len_len a) (len_len a) totlen_buf; let last0 : lbuffer uint8 (HD.block_len a) = sub last 0ul (HD.block_len a) in let last1 : lbuffer uint8 (HD.block_len a) = sub last (HD.block_len a) (HD.block_len a) in let h1 = ST.get() in assert (modifies (loc last) h0 h1); (last0,last1) #pop-options noextract let preserves_sub_disjoint_multi #lanes #len #len' (b:lbuffer uint8 len) (r:multibuf lanes len') = (forall a l (x:lbuffer a l). disjoint b x ==> disjoint_multi r x) inline_for_extraction noextract let load_last_t (a:sha2_alg) (m:m_spec{is_supported a m}) = totlen_buf:lbuffer uint8 (len_len a) -> len:size_t{v len <= block_length a} -> b:multibuf (lanes a m) len -> fin:size_t{v fin == block_length a \/ v fin == 2 * block_length a} -> last:lbuffer uint8 (size (lanes a m) *! 2ul *! HD.block_len a) -> Stack (multibuf (lanes a m) (HD.block_len a) & multibuf (lanes a m) (HD.block_len a)) (requires fun h -> live h totlen_buf /\ live_multi h b /\ live h last /\ disjoint_multi b last /\ disjoint last totlen_buf /\ as_seq h last == LSeq.create (lanes a m * 2 * block_length a) (u8 0)) (ensures fun h0 (l0,l1) h1 -> modifies (loc last) h0 h1 /\ live_multi h1 l0 /\ live_multi h1 l1 /\ preserves_sub_disjoint_multi last l0 /\ preserves_sub_disjoint_multi last l1 /\ (as_seq_multi h1 l0, as_seq_multi h1 l1) == SpecVec.load_last #a #m (as_seq h0 totlen_buf) (v fin) (v len) (as_seq_multi h0 b)) inline_for_extraction noextract val load_last1: #a:sha2_alg -> #m:m_spec{lanes a m = 1} -> load_last_t a m #push-options "--z3rlimit 250" let load_last1 #a #m totlen_buf len b fin last = let h0 = ST.get() in let b0 = b.(|0|) in let (l0,l1) = load_last_blocks #a totlen_buf len b0 fin last in let lb0 : multibuf (lanes a m) (HD.block_len a) = ntup1 l0 in let lb1 : multibuf (lanes a m) (HD.block_len a) = ntup1 l1 in let h1 = ST.get() in assert (modifies (loc last) h0 h1); NTup.eq_intro (as_seq_multi h0 b) (ntup1 (as_seq h0 b0)); NTup.eq_intro (as_seq_multi h1 lb0) (ntup1 (as_seq h1 l0)); NTup.eq_intro (as_seq_multi h1 lb1) (ntup1 (as_seq h1 l1)); assert ((as_seq_multi h1 lb0, as_seq_multi h1 lb1) == SpecVec.load_last1 #a #m (as_seq h0 totlen_buf) (v fin) (v len) (as_seq_multi h0 b)); reveal_opaque (`%SpecVec.load_last) (SpecVec.load_last #a #m); (lb0,lb1) #pop-options inline_for_extraction noextract val load_last4: #a:sha2_alg -> #m:m_spec{lanes a m = 4} -> load_last_t a m #push-options "--z3rlimit 350" let load_last4 #a #m totlen_buf len b fin last = let h0 = ST.get() in let (b0,(b1,(b2,b3))) = NTup.tup4 b in let last0 = sub last 0ul (2ul *! HD.block_len a) in let last1 = sub last (2ul *! HD.block_len a) (2ul *! HD.block_len a) in let last2 = sub last (4ul *! HD.block_len a) (2ul *! HD.block_len a) in let last3 = sub last (6ul *! HD.block_len a) (2ul *! HD.block_len a) in let h1 = ST.get() in assert (disjoint last0 last1); LSeq.eq_intro (as_seq h1 last0) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last1) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last2) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last3) (LSeq.create (2 * block_length a) (u8 0)); let (l00,l01) = load_last_blocks #a totlen_buf len b0 fin last0 in let (l10,l11) = load_last_blocks #a totlen_buf len b1 fin last1 in let (l20,l21) = load_last_blocks #a totlen_buf len b2 fin last2 in let (l30,l31) = load_last_blocks #a totlen_buf len b3 fin last3 in let mb0:multibuf (lanes a m) (HD.block_len a) = ntup4 (l00, (l10, (l20, l30))) in let mb1:multibuf (lanes a m) (HD.block_len a) = ntup4 (l01, (l11, (l21, l31))) in let h1 = ST.get() in assert ((as_seq h1 l00, as_seq h1 l01) == SpecVec.load_last_blocks #a (as_seq h0 totlen_buf) (v fin) (v len) (as_seq h0 b0)); assert ((as_seq h1 l10, as_seq h1 l11) == SpecVec.load_last_blocks #a (as_seq h0 totlen_buf) (v fin) (v len) (as_seq h0 b1)); assert ((as_seq h1 l20, as_seq h1 l21) == SpecVec.load_last_blocks #a (as_seq h0 totlen_buf) (v fin) (v len) (as_seq h0 b2)); assert ((as_seq h1 l30, as_seq h1 l31) == SpecVec.load_last_blocks #a (as_seq h0 totlen_buf) (v fin) (v len) (as_seq h0 b3)); NTup.eq_intro (as_seq_multi h1 mb0) (ntup4 (as_seq h1 l00, (as_seq h1 l10, (as_seq h1 l20, (as_seq h1 l30))))); NTup.eq_intro (as_seq_multi h1 mb1) (ntup4 (as_seq h1 l01, (as_seq h1 l11, (as_seq h1 l21, (as_seq h1 l31))))); assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3) h0 h1); assert (modifies (loc last) h0 h1); assert (live_multi h1 mb0); assert (live_multi h1 mb1); reveal_opaque (`%SpecVec.load_last) (SpecVec.load_last #a #m); (mb0, mb1) #pop-options inline_for_extraction noextract val load_last8: #a:sha2_alg -> #m:m_spec{lanes a m = 8} -> load_last_t a m
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntVector.Transpose.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Impl.SHA2.Types.fst.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA2.Core.fst" }
[ { "abbrev": true, "full_module": "Hacl.Hash.Definitions", "short_module": "HD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.IntVector.Transpose", "short_module": "VecTranspose" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": "SpecVec" }, { "abbrev": true, "full_module": "Lib.NTuple", "short_module": "NTup" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "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.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "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.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 600, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.SHA2.Core.load_last_t a m
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Hacl.Spec.SHA2.Vec.lanes", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Spec.Hash.Definitions.len_len", "Lib.IntTypes.size_t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.Hash.Definitions.block_length", "Lib.MultiBuffer.multibuf", "Prims.l_or", "Prims.eq2", "Lib.IntTypes.range", "Prims.op_disEquality", "FStar.Mul.op_Star", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "FStar.UInt32.__uint_to_t", "Hacl.Hash.Definitions.block_len", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Lib.Sequence.lseq", "Spec.Hash.Definitions.len_length", "Prims.nat", "Prims.op_GreaterThanOrEqual", "Hacl.Spec.SHA2.Vec.multiseq", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.SHA2.Vec.load_last", "Prims._assert", "Lib.MultiBuffer.as_seq_multi", "Hacl.Spec.SHA2.Vec.load_last8", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.NTuple.eq_intro", "FStar.Seq.Properties.lseq", "Lib.NTuple.ntup8", "Lib.MultiBuffer.live_multi", "Lib.NTuple.ntup8_lemma", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Lib.Buffer.op_Bar_Plus_Bar", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Hacl.Impl.SHA2.Core.load_last_blocks", "Lib.Sequence.eq_intro", "Lib.Sequence.create", "Lib.IntTypes.u8", "Lib.MultiBuffer.internally_disjoint8", "Lib.IntTypes.mul", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub", "Lib.NTuple.tup8" ]
[]
false
false
false
false
false
let load_last8 #a #m totlen_buf len b fin last =
let h0 = ST.get () in let b0, (b1, (b2, (b3, (b4, (b5, (b6, b7)))))) = NTup.tup8 b in let last0 = sub last 0ul (2ul *! HD.block_len a) in let last1 = sub last (2ul *! HD.block_len a) (2ul *! HD.block_len a) in let last2 = sub last (4ul *! HD.block_len a) (2ul *! HD.block_len a) in let last3 = sub last (6ul *! HD.block_len a) (2ul *! HD.block_len a) in let last4 = sub last (8ul *! HD.block_len a) (2ul *! HD.block_len a) in let last5 = sub last (10ul *! HD.block_len a) (2ul *! HD.block_len a) in let last6 = sub last (12ul *! HD.block_len a) (2ul *! HD.block_len a) in let last7 = sub last (14ul *! HD.block_len a) (2ul *! HD.block_len a) in assert (internally_disjoint8 last0 last1 last2 last3 last4 last5 last6 last7); let h1 = ST.get () in assert (h0 == h1); LSeq.eq_intro (as_seq h1 last0) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last1) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last2) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last3) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last4) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last5) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last6) (LSeq.create (2 * block_length a) (u8 0)); LSeq.eq_intro (as_seq h1 last7) (LSeq.create (2 * block_length a) (u8 0)); let l00, l01 = load_last_blocks #a totlen_buf len b0 fin last0 in let l10, l11 = load_last_blocks #a totlen_buf len b1 fin last1 in let h2 = ST.get () in assert (modifies (loc last0 |+| loc last1) h0 h2); let l20, l21 = load_last_blocks #a totlen_buf len b2 fin last2 in let l30, l31 = load_last_blocks #a totlen_buf len b3 fin last3 in let h2 = ST.get () in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3) h0 h2); let l40, l41 = load_last_blocks #a totlen_buf len b4 fin last4 in let l50, l51 = load_last_blocks #a totlen_buf len b5 fin last5 in let h2 = ST.get () in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3 |+| loc last4 |+| loc last5) h0 h2); let l60, l61 = load_last_blocks #a totlen_buf len b6 fin last6 in let l70, l71 = load_last_blocks #a totlen_buf len b7 fin last7 in let h3 = ST.get () in assert (modifies (loc last0 |+| loc last1 |+| loc last2 |+| loc last3 |+| loc last4 |+| loc last5 |+| loc last6 |+| loc last7) h0 h3); assert (modifies (loc last) h0 h3); let mb0:multibuf (lanes a m) (HD.block_len a) = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in let mb1:multibuf (lanes a m) (HD.block_len a) = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in ntup8_lemma #_ #8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))); ntup8_lemma #_ #8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))); assert (live_multi h3 mb0); assert (live_multi h3 mb1); NTup.eq_intro (as_seq_multi h3 mb0) (ntup8 (as_seq h3 l00, (as_seq h3 l10, (as_seq h3 l20, (as_seq h3 l30, (as_seq h3 l40, (as_seq h3 l50, (as_seq h3 l60, (as_seq h3 l70))))))))); NTup.eq_intro (as_seq_multi h3 mb1) (ntup8 (as_seq h3 l01, (as_seq h3 l11, (as_seq h3 l21, (as_seq h3 l31, (as_seq h3 l41, (as_seq h3 l51, (as_seq h3 l61, (as_seq h3 l71))))))))); assert ((as_seq_multi h3 mb0, as_seq_multi h3 mb1) == SpecVec.load_last8 #a #m (as_seq h0 totlen_buf) (v fin) (v len) (as_seq_multi h0 b)); reveal_opaque (`%SpecVec.load_last) (SpecVec.load_last #a #m); (mb0, mb1)
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_vec
val eval_vec (v: vec) (s: state) : quad32
val eval_vec (v: vec) (s: state) : quad32
let eval_vec (v:vec) (s:state) : quad32 = s.vecs v
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 103, "start_col": 7, "start_line": 103 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Vale.PPC64LE.Machine_s.vec -> s: Vale.PPC64LE.Machine_s.state -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Machine_s.vec", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.Def.Types_s.quad32" ]
[]
false
false
false
true
false
let eval_vec (v: vec) (s: state) : quad32 =
s.vecs v
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_reg
val eval_reg (r: reg) (s: state) : nat64
val eval_reg (r: reg) (s: state) : nat64
let eval_reg (r:reg) (s:state) : nat64 = s.regs r
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 102, "start_col": 7, "start_line": 102 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.PPC64LE.Machine_s.reg -> s: Vale.PPC64LE.Machine_s.state -> Vale.Def.Types_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.Def.Types_s.nat64" ]
[]
false
false
false
true
false
let eval_reg (r: reg) (s: state) : nat64 =
s.regs r
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_mem128
val eval_mem128 (ptr: int) (s: state) : quad32
val eval_mem128 (ptr: int) (s: state) : quad32
let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 105, "start_col": 7, "start_line": 105 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.state -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.MachineHeap_s.get_heap_val128", "Vale.Arch.Heap.heap_get", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.Def.Types_s.quad32" ]
[]
false
false
false
true
false
let eval_mem128 (ptr: int) (s: state) : quad32 =
get_heap_val128 ptr (heap_get s.ms_heap)
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_mem
val eval_mem (ptr: int) (s: state) : nat64
val eval_mem (ptr: int) (s: state) : nat64
let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap)
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 89, "end_line": 104, "start_col": 7, "start_line": 104 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.state -> Vale.Def.Types_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.MachineHeap_s.get_heap_val64", "Vale.Arch.Heap.heap_get", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.Def.Types_s.nat64" ]
[]
false
false
false
true
false
let eval_mem (ptr: int) (s: state) : nat64 =
get_heap_val64 ptr (heap_get s.ms_heap)
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_stack
val eval_stack (ptr: int) (s: machine_stack) : nat64
val eval_stack (ptr: int) (s: machine_stack) : nat64
let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 109, "start_col": 7, "start_line": 107 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap)
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.machine_stack -> Vale.Def.Types_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val64", "Vale.Def.Types_s.nat64" ]
[]
false
false
false
true
false
let eval_stack (ptr: int) (s: machine_stack) : nat64 =
let Machine_stack _ mem = s in get_heap_val64 ptr mem
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.eval_stack128
val eval_stack128 (ptr: int) (s: machine_stack) : quad32
val eval_stack128 (ptr: int) (s: machine_stack) : quad32
let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 112, "start_col": 7, "start_line": 110 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.machine_stack -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val128", "Vale.Def.Types_s.quad32" ]
[]
false
false
false
true
false
let eval_stack128 (ptr: int) (s: machine_stack) : quad32 =
let Machine_stack _ mem = s in get_heap_val128 ptr mem
false
Hacl.Spec.Bignum.Squaring.fst
Hacl.Spec.Bignum.Squaring.bn_sqr_loop_lemma
val bn_sqr_loop_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i) == eval_ aLen a i * eval_ aLen a i)
val bn_sqr_loop_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i) == eval_ aLen a i * eval_ aLen a i)
let rec bn_sqr_loop_lemma #t #aLen a i = let pbits = bits t in let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in if i = 0 then begin bn_eval0 acc; bn_eval0 tmp; bn_eval0 a end else begin let p1 = pow2 (pbits * (i + i - 1)) in let p2 = pow2 (pbits * (i + i - 2)) in let p3 = pow2 (pbits * (i - 1)) in let acc1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_f a) bn_zero in let tmp1 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) bn_zero in unfold_repeati i (bn_sqr_f a) bn_zero (i - 1); assert (acc == bn_sqr_f a (i - 1) acc1); bn_sqr_f_lemma a (i - 1) acc1 (i + i - 1); assert (acc.[i + i - 1] == acc1.[i + i - 1]); bn_sqr_tail a (i - 1); assert (acc.[i + i - 1] == uint #t 0); calc (==) { 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i); (==) { bn_sqr_diag_loop_step a i } 2 * eval_ resLen acc (i + i) + eval_ resLen tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_unfold_i acc (i + i) } 2 * (eval_ resLen acc (i + i - 1) + v acc.[i + i - 1] * p1) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Classical.forall_intro (bn_sqr_f_lemma a (i - 1) acc1) } 2 * (eval_ resLen acc1 (i + i - 2) + eval_ aLen a (i - 1) * v a.[i - 1] * p3) + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.distributivity_add_right 2 (eval_ resLen acc1 (i + i - 2)) (eval_ aLen a (i - 1) * v a.[i - 1] * p3) } 2 * eval_ resLen acc1 (i + i - 2) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + eval_ (aLen + aLen) tmp1 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_sqr_loop_lemma a (i - 1) } eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * p3 + v a.[i - 1] * v a.[i - 1] * p2; (==) { bn_eval_square a i } eval_ aLen a i * eval_ aLen a i; }; () end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Squaring.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 386, "start_col": 0, "start_line": 343 }
module Hacl.Spec.Bignum.Squaring open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib module SM = Hacl.Spec.Bignum.Multiplication module SA = Hacl.Spec.Bignum.Addition #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sqr_diag_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_diag_f #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let acc = acc.[2 * i] <- lo in let acc = acc.[2 * i + 1] <- hi in acc val bn_sqr_diag: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr_diag #t #aLen a = let acc0 = create (aLen + aLen) (uint #t 0) in repeati aLen (bn_sqr_diag_f a) acc0 val bn_sqr_f: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> lbignum t (aLen + aLen) let bn_sqr_f #t #aLen a j acc = let c, acc = SM.bn_mul1_lshift_add (sub a 0 j) a.[j] j acc in acc.[j + j] <- c val bn_sqr: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> lbignum t (aLen + aLen) let bn_sqr #t #aLen a = let res = create (aLen + aLen) (uint #t 0) in let res = repeati aLen (bn_sqr_f a) res in let c, res = Hacl.Spec.Bignum.Addition.bn_add res res in let tmp = bn_sqr_diag a in let c, res = Hacl.Spec.Bignum.Addition.bn_add res tmp in res val bn_sqr_diag_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i < aLen} -> acc:lbignum t (aLen + aLen) -> Lemma (let (hi, lo) = mul_wide a.[i] a.[i] in let res = bn_sqr_diag_f a i acc in res.[2 * i] == lo /\ res.[2 * i + 1] == hi /\ (forall (i0:nat{i0 < aLen /\ i0 <> i}). acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1])) let bn_sqr_diag_f_lemma #t #aLen a i acc = let (hi, lo) = mul_wide a.[i] a.[i] in let res1 = acc.[2 * i] <- lo in let res = res1.[2 * i + 1] <- hi in let aux (i0:nat{i0 < aLen + aLen /\ i0 <> 2 * i /\ i0 <> 2 * i + 1}) : Lemma (acc.[i0] == res.[i0]) = () in let aux2 (i0:nat{i0 < aLen /\ i0 <> i}) : Lemma (acc.[2 * i0] == res.[2 * i0] /\ acc.[2 * i0 + 1] == res.[2 * i0 + 1]) = aux (2 * i0); //assert (acc.[2 * i0] == res.[2 * i0]); aux (2 * i0 + 1); //assert (acc.[2 * i0 + 1] == res.[2 * i0 + 1]); () in Classical.forall_intro aux2 val bn_sqr_diag_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_diag_f a) acc0 /\ (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index res (2 * i) == lo /\ Seq.index res (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index res (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index res (2 * i + 1) == Seq.index acc0 (2 * i + 1)))) let bn_sqr_diag_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_diag_f a) acc0; repeati_inductive k (fun i acci -> acci == repeati i (bn_sqr_diag_f a) acc0 /\ (forall (i0:nat{i0 < i}). let (hi, lo) = mul_wide a.[i0] a.[i0] in Seq.index acci (2 * i0) == lo /\ Seq.index acci (2 * i0 + 1) == hi) /\ (forall (i0:nat{i <= i0 /\ i0 < aLen}). Seq.index acci (2 * i0) == Seq.index acc0 (2 * i0) /\ Seq.index acci (2 * i0 + 1) == Seq.index acc0 (2 * i0 + 1))) (fun i acci -> unfold_repeati k (bn_sqr_diag_f a) acc0 i; let acc = bn_sqr_diag_f a i acci in bn_sqr_diag_f_lemma #t #aLen a i acci; acc) acc0 val bn_sqr_diag_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in (forall (i:nat{i < k}). let (hi, lo) = mul_wide a.[i] a.[i] in Seq.index acc (2 * i) == lo /\ Seq.index acc (2 * i + 1) == hi) /\ (forall (i:nat{k <= i /\ i < aLen}). Seq.index acc (2 * i) == Seq.index acc0 (2 * i) /\ Seq.index acc (2 * i + 1) == Seq.index acc0 (2 * i + 1))) let bn_sqr_diag_lemma #t #aLen a k = let _ = bn_sqr_diag_inductive a k in () val bn_sqr_diag_eq: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k < aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in slice acc1 0 (2 * k) == slice acc2 0 (2 * k)) let bn_sqr_diag_eq #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati k (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (k + 1) (bn_sqr_diag_f a) acc0 in let aux (i:nat{i < 2 * k}) : Lemma (Seq.index acc1 i == Seq.index acc2 i) = let i2 = i / 2 in bn_sqr_diag_lemma a k; bn_sqr_diag_lemma a (k + 1); assert (Seq.index acc1 (2 * i2) == Seq.index acc2 (2 * i2) /\ Seq.index acc1 (2 * i2 + 1) == Seq.index acc2 (2 * i2 + 1)); Math.Lemmas.euclidean_division_definition i 2; assert (Seq.index acc1 i == Seq.index acc2 i) in Classical.forall_intro aux; eq_intro (slice acc1 0 (2 * k)) (slice acc2 0 (2 * k)) val bn_sqr_diag_loop_step: #t:limb_t -> #aLen:size_pos{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_sqr_diag_loop_step #t #aLen a i = let pbits = bits t in let acc0 = create (aLen + aLen) (uint #t 0) in let acc1 : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) acc0 in let acc2 : lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) acc0 in bn_eval_unfold_i acc1 (i + i); bn_eval_unfold_i acc1 (i + i - 1); //assert (eval_ (aLen + aLen) acc1 (i + i) == //eval_ (aLen + aLen) acc1 (i + i - 2) + v acc1.[i + i - 2] * (pow2 (p * (i + i - 2))) + v acc1.[i + i - 1] * pow2 (p * (i + i - 1))); calc (==) { v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * pow2 (pbits * (i + i - 1)); (==) { Math.Lemmas.pow2_plus (pbits * (i + i - 2)) pbits } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + v acc1.[i + i - 1] * (pow2 (pbits * (i + i - 2)) * pow2 pbits); (==) { Math.Lemmas.paren_mul_right (v acc1.[i + i - 1]) (pow2 pbits) (pow2 (pbits * (i + i - 2))) } v acc1.[i + i - 2] * pow2 (pbits * (i + i - 2)) + (v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { Math.Lemmas.distributivity_add_left (v acc1.[i + i - 2]) (v acc1.[i + i - 1] * pow2 pbits) (pow2 (pbits * (i + i - 2))) } (v acc1.[i + i - 2] + v acc1.[i + i - 1] * pow2 pbits) * pow2 (pbits * (i + i - 2)); (==) { bn_sqr_diag_lemma a i } v a.[i - 1] * v a.[i - 1] * pow2 (pbits * (i + i - 2)); }; bn_sqr_diag_eq a (i - 1); bn_eval_extensionality_j acc1 acc2 (i + i - 2); assert (eval_ (aLen + aLen) acc1 (i + i) == eval_ (aLen + aLen) acc2 (i + i - 2) + v a.[i - 1] * v a.[i - 1] * (pow2 (pbits * (i + i - 2)))) val bn_sqr_f_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> j:size_nat{j < aLen} -> acc:lbignum t (aLen + aLen) -> i:nat{j + j < i /\ i < aLen + aLen} -> Lemma (let res = bn_sqr_f a j acc in eval_ (aLen + aLen) res (j + j + 1) == eval_ (aLen + aLen) acc (j + j) + eval_ aLen a j * v a.[j] * pow2 (bits t * j) /\ Seq.index res i == Seq.index acc i) let bn_sqr_f_lemma #t #aLen a j acc i = let resLen = aLen + aLen in let c, acc' = SM.bn_mul1_add_in_place #t #j (sub a 0 j) a.[j] (sub acc j j) in let acc1 = update_sub acc j j acc' in assert (index acc1 i == index acc i); let res = acc1.[j + j] <- c in assert (index res i == index acc i); SM.bn_mul1_lshift_add_lemma #t #j #resLen (sub a 0 j) a.[j] j acc; bn_eval_extensionality_j acc1 res (j + j); bn_eval_unfold_i res (j + j + 1); bn_eval_extensionality_j a (sub a 0 j) j val bn_sqr_inductive: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Pure (lbignum t (aLen + aLen)) (requires True) (ensures fun res -> (let acc0 = create (aLen + aLen) (uint #t 0) in res == repeati k (bn_sqr_f a) acc0 /\ (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index res i == Seq.index acc0 i))) let bn_sqr_inductive #t #aLen a k = let acc0 = create (aLen + aLen) (uint #t 0) in eq_repeati0 k (bn_sqr_f a) acc0; repeati_inductive #(lbignum t (aLen + aLen)) k (fun i acci -> acci == repeati i (bn_sqr_f a) acc0 /\ (forall (i0:nat{i + i < i0 /\ i0 < aLen + aLen}). Seq.index acci i0 == Seq.index acc0 i0)) (fun i acci -> unfold_repeati k (bn_sqr_f a) acc0 i; let acc1 = bn_sqr_f a i acci in assert (acc1 == repeati (i + 1) (bn_sqr_f a) acc0); Classical.forall_intro (bn_sqr_f_lemma a i acci); assert (forall (i0:nat{i + i + 2 < i0 /\ i0 < aLen + aLen}). Seq.index acc1 i0 == Seq.index acc0 i0); acc1) acc0 val bn_sqr_tail: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> k:nat{k <= aLen} -> Lemma (let acc0 = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati k (bn_sqr_f a) acc0 in (forall (i:nat{k + k < i /\ i < aLen + aLen}). Seq.index acc i == uint #t 0)) let bn_sqr_tail #t #aLen a k = let _ = bn_sqr_inductive a k in () val square_of_sum: a:nat -> b:nat -> Lemma ((a + b) * (a + b) == a * a + 2 * a * b + b * b) let square_of_sum a b = () val bn_eval_square: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:pos{i <= aLen} -> Lemma (eval_ aLen a i * eval_ aLen a i == eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + 2 * eval_ aLen a (i - 1) * v a.[i - 1] * pow2 (bits t * (i - 1)) + v a.[i - 1] * v a.[i - 1] * pow2 (bits t * (i + i - 2))) let bn_eval_square #t #aLen a i = let e1 = eval_ aLen a (i - 1) in let p1 = pow2 (bits t * (i - 1)) in let p2 = pow2 (bits t * (i + i - 2)) in calc (==) { eval_ aLen a i * eval_ aLen a i; (==) { bn_eval_unfold_i a i } (e1 + v a.[i - 1] * p1) * (e1 + v a.[i - 1] * p1); (==) { square_of_sum e1 (v a.[i - 1] * p1) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + (v a.[i - 1] * p1) * (v a.[i - 1] * p1); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) p1 (v a.[i - 1] * p1); Math.Lemmas.paren_mul_right p1 p1 (v a.[i - 1]) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p1 * p1 * v a.[i - 1]); (==) { Math.Lemmas.pow2_plus (bits t * (i - 1)) (bits t * (i - 1)) } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * (p2 * v a.[i - 1]); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v a.[i - 1]) p2 } e1 * e1 + 2 * e1 * (v a.[i - 1] * p1) + v a.[i - 1] * v a.[i - 1] * p2; (==) { Math.Lemmas.paren_mul_right (2 * e1) (v a.[i - 1]) p1 } e1 * e1 + 2 * e1 * v a.[i - 1] * p1 + v a.[i - 1] * v a.[i - 1] * p2; } val bn_sqr_loop_lemma: #t:limb_t -> #aLen:size_nat{aLen + aLen <= max_size_t} -> a:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc : lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp : lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i) == eval_ aLen a i * eval_ aLen a i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Seq.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.Bignum.Squaring.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Addition", "short_module": "SA" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Multiplication", "short_module": "SM" }, { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 75, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i <= aLen} -> FStar.Pervasives.Lemma (ensures (let resLen = aLen + aLen in let bn_zero = Lib.Sequence.create (aLen + aLen) (Lib.IntTypes.uint 0) in let acc = Lib.LoopCombinators.repeati i (Hacl.Spec.Bignum.Squaring.bn_sqr_f a) bn_zero in let tmp = Lib.LoopCombinators.repeati i (Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f a) bn_zero in 2 * Hacl.Spec.Bignum.Definitions.eval_ resLen acc (i + i) + Hacl.Spec.Bignum.Definitions.eval_ resLen tmp (i + i) == Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Hacl.Spec.Bignum.Definitions.eval_ aLen a i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Prims.unit", "Prims.bool", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_loop_step", "Prims.squash", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.op_LessThan", "Hacl.Spec.Bignum.Squaring.bn_sqr_f", "Prims.pow2", "Lib.IntTypes.bits", "FStar.Seq.Base.index", "Hacl.Spec.Bignum.Squaring.bn_sqr_f_lemma", "FStar.Math.Lemmas.distributivity_add_right", "Hacl.Spec.Bignum.Squaring.bn_sqr_loop_lemma", "Hacl.Spec.Bignum.Squaring.bn_eval_square", "Prims._assert", "Lib.IntTypes.int_t", "Prims.l_or", "Lib.IntTypes.range", "Lib.Sequence.to_seq", "Lib.IntTypes.uint", "Hacl.Spec.Bignum.Squaring.bn_sqr_tail", "Lib.LoopCombinators.unfold_repeati", "Lib.LoopCombinators.repeati", "Hacl.Spec.Bignum.Squaring.bn_sqr_diag_f", "Prims.pos", "Lib.Sequence.lseq", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.create" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_sqr_loop_lemma #t #aLen a i =
let pbits = bits t in let resLen = aLen + aLen in let bn_zero = create (aLen + aLen) (uint #t 0) in let acc:lbignum t (aLen + aLen) = repeati i (bn_sqr_f a) bn_zero in let tmp:lbignum t (aLen + aLen) = repeati i (bn_sqr_diag_f a) bn_zero in if i = 0 then (bn_eval0 acc; bn_eval0 tmp; bn_eval0 a) else let p1 = pow2 (pbits * (i + i - 1)) in let p2 = pow2 (pbits * (i + i - 2)) in let p3 = pow2 (pbits * (i - 1)) in let acc1:lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_f a) bn_zero in let tmp1:lbignum t (aLen + aLen) = repeati (i - 1) (bn_sqr_diag_f a) bn_zero in unfold_repeati i (bn_sqr_f a) bn_zero (i - 1); assert (acc == bn_sqr_f a (i - 1) acc1); bn_sqr_f_lemma a (i - 1) acc1 (i + i - 1); assert (acc.[ i + i - 1 ] == acc1.[ i + i - 1 ]); bn_sqr_tail a (i - 1); assert (acc.[ i + i - 1 ] == uint #t 0); calc ( == ) { 2 * eval_ resLen acc (i + i) + eval_ resLen tmp (i + i); ( == ) { bn_sqr_diag_loop_step a i } 2 * eval_ resLen acc (i + i) + eval_ resLen tmp1 (i + i - 2) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { bn_eval_unfold_i acc (i + i) } 2 * (eval_ resLen acc (i + i - 1) + v acc.[ i + i - 1 ] * p1) + eval_ (aLen + aLen) tmp1 (i + i - 2) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { Classical.forall_intro (bn_sqr_f_lemma a (i - 1) acc1) } 2 * (eval_ resLen acc1 (i + i - 2) + (eval_ aLen a (i - 1) * v a.[ i - 1 ]) * p3) + eval_ (aLen + aLen) tmp1 (i + i - 2) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { Math.Lemmas.distributivity_add_right 2 (eval_ resLen acc1 (i + i - 2)) ((eval_ aLen a (i - 1) * v a.[ i - 1 ]) * p3) } 2 * eval_ resLen acc1 (i + i - 2) + ((2 * eval_ aLen a (i - 1)) * v a.[ i - 1 ]) * p3 + eval_ (aLen + aLen) tmp1 (i + i - 2) + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { bn_sqr_loop_lemma a (i - 1) } eval_ aLen a (i - 1) * eval_ aLen a (i - 1) + ((2 * eval_ aLen a (i - 1)) * v a.[ i - 1 ]) * p3 + (v a.[ i - 1 ] * v a.[ i - 1 ]) * p2; ( == ) { bn_eval_square a i } eval_ aLen a i * eval_ aLen a i; }; ()
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_stack64'
val update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack
val update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack
let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 218, "start_col": 0, "start_line": 215 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> s: Vale.PPC64LE.Machine_s.machine_stack -> Vale.PPC64LE.Machine_s.machine_stack
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.nat64", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.PPC64LE.Machine_s.Machine_stack", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.update_heap64" ]
[]
false
false
false
true
false
let update_stack64' (ptr: int) (v: nat64) (s: machine_stack) : machine_stack =
let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_stack128'
val update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack
val update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack
let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 224, "start_col": 0, "start_line": 221 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> s: Vale.PPC64LE.Machine_s.machine_stack -> Vale.PPC64LE.Machine_s.machine_stack
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.PPC64LE.Machine_s.Machine_stack", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.update_heap128" ]
[]
false
false
false
true
false
let update_stack128' (ptr: int) (v: quad32) (s: machine_stack) : machine_stack =
let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_stack_and_taint
val update_stack_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state
val update_stack_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state
let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; }
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 231, "start_col": 0, "start_line": 226 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> s: Vale.PPC64LE.Machine_s.state -> t: Vale.Arch.HeapTypes_s.taint -> Vale.PPC64LE.Machine_s.state
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.nat64", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.HeapTypes_s.taint", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__cr0", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Semantics_s.update_stack64'", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Semantics_s.update_n", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Vale.PPC64LE.Machine_s.machine_stack" ]
[]
false
false
false
true
false
let update_stack_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state =
let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t }
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_stack128_and_taint
val update_stack128_and_taint (ptr: int) (v: quad32) (s: state) (t: taint) : state
val update_stack128_and_taint (ptr: int) (v: quad32) (s: state) (t: taint) : state
let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t }
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 238, "start_col": 0, "start_line": 233 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; }
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.quad32 -> s: Vale.PPC64LE.Machine_s.state -> t: Vale.Arch.HeapTypes_s.taint -> Vale.PPC64LE.Machine_s.state
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.HeapTypes_s.taint", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__cr0", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Semantics_s.update_stack128'", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Semantics_s.update_n", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Vale.PPC64LE.Machine_s.machine_stack" ]
[]
false
false
false
true
false
let update_stack128_and_taint (ptr: int) (v: quad32) (s: state) (t: taint) : state =
let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t }
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.valid_src_stack64
val valid_src_stack64 (ptr: int) (st: machine_stack) : bool
val valid_src_stack64 (ptr: int) (st: machine_stack) : bool
let valid_src_stack64 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr64 ptr mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 243, "start_col": 0, "start_line": 241 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; } let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t }
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> st: Vale.PPC64LE.Machine_s.machine_stack -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.valid_addr64", "Prims.bool" ]
[]
false
false
false
true
false
let valid_src_stack64 (ptr: int) (st: machine_stack) : bool =
let Machine_stack init_r1 mem = st in valid_addr64 ptr mem
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.valid_src_stack128
val valid_src_stack128 (ptr: int) (st: machine_stack) : bool
val valid_src_stack128 (ptr: int) (st: machine_stack) : bool
let valid_src_stack128 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr128 ptr mem
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 248, "start_col": 0, "start_line": 246 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; } let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t } unfold let valid_src_stack64 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr64 ptr mem
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> st: Vale.PPC64LE.Machine_s.machine_stack -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.valid_addr128", "Prims.bool" ]
[]
false
false
false
true
false
let valid_src_stack128 (ptr: int) (st: machine_stack) : bool =
let Machine_stack init_r1 mem = st in valid_addr128 ptr mem
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.valid_src_stack64_and_taint
val valid_src_stack64_and_taint (ptr: int) (s: state) (t: taint) : bool
val valid_src_stack64_and_taint (ptr: int) (s: state) (t: taint) : bool
let valid_src_stack64_and_taint (ptr:int) (s:state) (t:taint) : bool = valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 252, "start_col": 0, "start_line": 251 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; } let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t } unfold let valid_src_stack64 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr64 ptr mem unfold let valid_src_stack128 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr128 ptr mem
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.state -> t: Vale.Arch.HeapTypes_s.taint -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.HeapTypes_s.taint", "Prims.op_AmpAmp", "Vale.PPC64LE.Semantics_s.valid_src_stack64", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Semantics_s.match_n", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.bool" ]
[]
false
false
false
true
false
let valid_src_stack64_and_taint (ptr: int) (s: state) (t: taint) : bool =
valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.match_n
val match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (b: bool { b <==> (forall i. {:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n)
val match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (b: bool { b <==> (forall i. {:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n)
let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 130, "start_col": 0, "start_line": 122 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *)
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
addr: Prims.int -> n: Prims.nat -> memTaint: Vale.Arch.HeapTypes_s.memTaint_t -> t: Vale.Arch.HeapTypes_s.taint -> Prims.Tot (b: Prims.bool { b <==> (forall (i: Prims.int). {:pattern FStar.Map.sel memTaint i} i >= addr /\ i < addr + n ==> memTaint.[ i ] == t) })
Prims.Tot
[ "total", "" ]
[]
[ "Prims.int", "Prims.nat", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.Arch.HeapTypes_s.taint", "Prims.op_Equality", "Prims.bool", "Prims.op_disEquality", "Vale.PPC64LE.Semantics_s.op_String_Access", "Vale.PPC64LE.Semantics_s.match_n", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.l_iff", "Prims.b2t", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "FStar.Map.sel" ]
[ "recursion" ]
false
false
false
false
false
let rec match_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (b: bool { b <==> (forall i. {:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[ i ] == t) }) (decreases n) =
if n = 0 then true else if memTaint.[ addr ] <> t then false else match_n (addr + 1) (n - 1) memTaint t
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_n
val update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (m: memTaint_t { (forall i. {:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n)
val update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (m: memTaint_t { (forall i. {:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n)
let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 141, "start_col": 0, "start_line": 133 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
addr: Prims.int -> n: Prims.nat -> memTaint: Vale.Arch.HeapTypes_s.memTaint_t -> t: Vale.Arch.HeapTypes_s.taint -> Prims.Tot (m: Vale.Arch.HeapTypes_s.memTaint_t { forall (i: Prims.int). {:pattern FStar.Map.sel m i} (i >= addr /\ i < addr + n ==> m.[ i ] == t) /\ (i < addr \/ i >= addr + n ==> m.[ i ] == memTaint.[ i ]) })
Prims.Tot
[ "total", "" ]
[]
[ "Prims.int", "Prims.nat", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.Arch.HeapTypes_s.taint", "Prims.op_Equality", "Prims.bool", "Vale.PPC64LE.Semantics_s.update_n", "Prims.op_Addition", "Prims.op_Subtraction", "Vale.PPC64LE.Semantics_s.op_String_Assignment", "Prims.l_Forall", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "Vale.PPC64LE.Semantics_s.op_String_Access", "Prims.l_or", "FStar.Map.sel" ]
[ "recursion" ]
false
false
false
false
false
let rec update_n (addr: int) (n: nat) (memTaint: memTaint_t) (t: taint) : Tot (m: memTaint_t { (forall i. {:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[ i ] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[ i ] == memTaint.[ i ])) }) (decreases n) =
if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[ addr ] <- t) t
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.valid_src_stack128_and_taint
val valid_src_stack128_and_taint (ptr: int) (s: state) (t: taint) : bool
val valid_src_stack128_and_taint (ptr: int) (s: state) (t: taint) : bool
let valid_src_stack128_and_taint (ptr:int) (s:state) (t:taint) : bool = valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 71, "end_line": 256, "start_col": 0, "start_line": 255 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; } let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t } unfold let valid_src_stack64 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr64 ptr mem unfold let valid_src_stack128 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr128 ptr mem unfold let valid_src_stack64_and_taint (ptr:int) (s:state) (t:taint) : bool = valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> s: Vale.PPC64LE.Machine_s.state -> t: Vale.Arch.HeapTypes_s.taint -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.HeapTypes_s.taint", "Prims.op_AmpAmp", "Vale.PPC64LE.Semantics_s.valid_src_stack128", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Semantics_s.match_n", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.bool" ]
[]
false
false
false
true
false
let valid_src_stack128_and_taint (ptr: int) (s: state) (t: taint) : bool =
valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.valid_src_stack
val valid_src_stack (r: reg) (s: state) : bool
val valid_src_stack (r: reg) (s: state) : bool
let valid_src_stack (r:reg) (s:state) : bool = valid_src_stack64 (eval_reg r s) s.ms_stack
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 259, "start_col": 0, "start_line": 258 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let lemma_is_machine_heap_update128 (ptr:int) (v:quad32) (mh:machine_heap) : Lemma (requires valid_addr128 ptr mh) (ensures is_machine_heap_update mh (update_heap128 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap128 ptr v mh))] = let lemma_is_machine_heap_update32 (ptr:int) (v:nat32) (mh:machine_heap) : Lemma (requires valid_addr ptr mh /\ valid_addr (ptr + 1) mh /\ valid_addr (ptr + 2) mh /\ valid_addr (ptr + 3) mh ) (ensures is_machine_heap_update mh (update_heap32 ptr v mh)) = update_heap32_reveal () in let mem1 = update_heap32 ptr v.lo0 mh in let mem2 = update_heap32 (ptr + 4) v.lo1 mem1 in let mem3 = update_heap32 (ptr + 8) v.hi2 mem2 in reveal_opaque (`%valid_addr128) valid_addr128; update_heap128_reveal (); lemma_is_machine_heap_update32 ptr v.lo0 mh; lemma_is_machine_heap_update32 (ptr + 4) v.lo1 mem1; lemma_is_machine_heap_update32 (ptr + 8) v.hi2 mem2; lemma_is_machine_heap_update32 (ptr + 12) v.hi3 mem3 let update_mem128 (ptr:int) (v:quad32) (s:state) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s let update_mem128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = if valid_addr128 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap128 ptr v (heap_get s.ms_heap)) (update_n ptr 16 (heap_taint s.ms_heap) t) } else s unfold let update_stack64' (ptr:int) (v:nat64) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap64 ptr v mem in Machine_stack init_r1 mem unfold let update_stack128' (ptr:int) (v:quad32) (s:machine_stack) : machine_stack = let Machine_stack init_r1 mem = s in let mem = update_heap128 ptr v mem in Machine_stack init_r1 mem let update_stack_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack64' ptr v s.ms_stack; ms_stackTaint = update_n ptr 8 s.ms_stackTaint t; } let update_stack128_and_taint (ptr:int) (v:quad32) (s:state) (t:taint) : state = let Machine_stack init_r1 mem = s.ms_stack in { s with ms_stack = update_stack128' ptr v s.ms_stack; ms_stackTaint = update_n ptr 16 s.ms_stackTaint t } unfold let valid_src_stack64 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr64 ptr mem unfold let valid_src_stack128 (ptr:int) (st:machine_stack) : bool = let Machine_stack init_r1 mem = st in valid_addr128 ptr mem unfold let valid_src_stack64_and_taint (ptr:int) (s:state) (t:taint) : bool = valid_src_stack64 ptr s.ms_stack && match_n ptr 8 s.ms_stackTaint t unfold let valid_src_stack128_and_taint (ptr:int) (s:state) (t:taint) : bool = valid_src_stack128 ptr s.ms_stack && match_n ptr 16 s.ms_stackTaint t
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Vale.PPC64LE.Machine_s.reg -> s: Vale.PPC64LE.Machine_s.state -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Semantics_s.valid_src_stack64", "Vale.PPC64LE.Semantics_s.eval_reg", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Prims.bool" ]
[]
false
false
false
true
false
let valid_src_stack (r: reg) (s: state) : bool =
valid_src_stack64 (eval_reg r s) s.ms_stack
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_mem
val update_mem (ptr: int) (v: nat64) (s: state) : state
val update_mem (ptr: int) (v: nat64) (s: state) : state
let update_mem (ptr:int) (v:nat64) (s:state) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 169, "start_col": 0, "start_line": 162 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); () let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> s: Vale.PPC64LE.Machine_s.state -> Vale.PPC64LE.Machine_s.state
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.nat64", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.MachineHeap_s.valid_addr64", "Vale.Arch.Heap.heap_get", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__cr0", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.Arch.Heap.heap_upd", "Vale.Arch.MachineHeap_s.update_heap64", "Vale.Arch.Heap.heap_taint", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.bool" ]
[]
false
false
false
true
false
let update_mem (ptr: int) (v: nat64) (s: state) : state =
if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (heap_taint s.ms_heap) } else s
false
Vale.PPC64LE.Semantics_s.fst
Vale.PPC64LE.Semantics_s.update_mem_and_taint
val update_mem_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state
val update_mem_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state
let update_mem_and_taint (ptr:int) (v:nat64) (s:state) (t:taint) : state = if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s
{ "file_name": "vale/specs/hardware/Vale.PPC64LE.Semantics_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 160, "start_col": 0, "start_line": 153 }
module Vale.PPC64LE.Semantics_s open FStar.Mul open FStar.Seq.Base open Vale.PPC64LE.Machine_s open Vale.Def.Words_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s include Vale.Arch.MachineHeap_s open Vale.Arch.HeapTypes_s open Vale.Arch.Heap open Vale.Arch.Types open Vale.Def.Sel open Vale.SHA2.Wrapper let (.[]) = Map.sel let (.[]<-) = Map.upd type ins = | Move : dst:reg -> src:reg -> ins | Load64 : dst:reg -> base:reg -> offset:int -> ins | Store64 : src:reg -> base:reg -> offset:int -> ins | LoadImm64 : dst:reg -> src:simm16 -> ins | LoadImmShl64 : dst:reg -> src:simm16 -> ins | AddLa : dst:reg -> src1:reg -> src2:simm16 -> ins | Add : dst:reg -> src1:reg -> src2:reg -> ins | AddImm : dst:reg -> src1:reg -> src2:simm16 -> ins | AddCarry : dst:reg -> src1:reg -> src2:reg -> ins | AddExtended : dst:reg -> src1:reg -> src2:reg -> ins | AddExtendedOV: dst:reg -> src1:reg -> src2:reg -> ins | Sub : dst:reg -> src1:reg -> src2:reg -> ins | SubImm : dst:reg -> src1:reg -> src2:nsimm16 -> ins | MulLow64 : dst:reg -> src1:reg -> src2:reg -> ins | MulHigh64U : dst:reg -> src1:reg -> src2:reg -> ins | Xor : dst:reg -> src1:reg -> src2:reg -> ins | And : dst:reg -> src1:reg -> src2:reg -> ins | Sr64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sl64Imm : dst:reg -> src1:reg -> src2:bits64 -> ins | Sr64 : dst:reg -> src1:reg -> src2:reg -> ins | Sl64 : dst:reg -> src1:reg -> src2:reg -> ins | Vmr : dst:vec -> src:vec -> ins | Mfvsrd : dst:reg -> src:vec -> ins | Mfvsrld : dst:reg -> src:vec -> ins | Mtvsrdd : dst:vec -> src1:reg -> src2:reg -> ins | Mtvsrws : dst:vec -> src:reg -> ins | Vadduwm : dst:vec -> src1:vec -> src2:vec -> ins | Vxor : dst:vec -> src1:vec -> src2:vec -> ins | Vand : dst:vec -> src1:vec -> src2:vec -> ins | Vslw : dst:vec -> src1:vec -> src2:vec -> ins | Vsrw : dst:vec -> src1:vec -> src2:vec -> ins | Vsl : dst:vec -> src1:vec -> src2:vec -> ins | Vcmpequw : dst:vec -> src1:vec -> src2:vec -> ins | Vsldoi : dst:vec -> src1:vec -> src2:vec -> count:quad32bytes -> ins | Vmrghw : dst:vec -> src1:vec -> src2:vec -> ins | Xxmrghd : dst:vec -> src1:vec -> src2:vec -> ins | Vsel : dst:vec -> src1:vec -> src2:vec -> sel:vec -> ins | Vspltw : dst:vec -> src:vec -> uim:nat2 -> ins | Vspltisw : dst:vec -> src:sim -> ins | Vspltisb : dst:vec -> src:sim -> ins | Load128 : dst:vec -> base:reg -> offset:reg -> ins | Store128 : src:vec -> base:reg -> offset:reg -> ins | Load128Word4 : dst:vec -> base:reg -> ins | Load128Word4Index : dst:vec -> base:reg -> offset:reg -> ins | Store128Word4: src:vec -> base:reg -> ins | Store128Word4Index: src:vec -> base:reg -> offset:reg -> ins | Load128Byte16: dst:vec -> base:reg -> ins | Load128Byte16Index: dst:vec -> base:reg -> offset:reg -> ins | Store128Byte16: src:vec -> base:reg -> ins | Store128Byte16Index: src:vec -> base:reg -> offset:reg -> ins | Vshasigmaw0 : dst:vec -> src:vec -> ins | Vshasigmaw1 : dst:vec -> src:vec -> ins | Vshasigmaw2 : dst:vec -> src:vec -> ins | Vshasigmaw3 : dst:vec -> src:vec -> ins | Vsbox : dst:vec -> src:vec -> ins | RotWord : dst:vec -> src1:vec -> src2:vec -> ins | Vcipher : dst:vec -> src1:vec -> src2:vec -> ins | Vcipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vncipher : dst:vec -> src1:vec -> src2:vec -> ins | Vncipherlast : dst:vec -> src1:vec -> src2:vec -> ins | Vpmsumd : dst:vec -> src1:vec -> src2:vec -> ins | Alloc : n:nat64 -> ins | Dealloc : n:nat64 -> ins | StoreStack128: src:vec -> t:taint -> offset:int -> ins | LoadStack128 : dst:vec -> t:taint -> offset:int -> ins | StoreStack64 : src:reg -> t:taint -> offset:int -> ins | LoadStack64 : dst:reg -> t:taint -> offset:int -> ins | Ghost : (_:unit) -> ins type ocmp = | OEq: o1:cmp_opr -> o2:cmp_opr -> ocmp | ONe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGe: o1:cmp_opr -> o2:cmp_opr -> ocmp | OLt: o1:cmp_opr -> o2:cmp_opr -> ocmp | OGt: o1:cmp_opr -> o2:cmp_opr -> ocmp type code = precode ins ocmp type codes = list code unfold let eval_reg (r:reg) (s:state) : nat64 = s.regs r unfold let eval_vec (v:vec) (s:state) : quad32 = s.vecs v unfold let eval_mem (ptr:int) (s:state) : nat64 = get_heap_val64 ptr (heap_get s.ms_heap) unfold let eval_mem128 (ptr:int) (s:state) : quad32 = get_heap_val128 ptr (heap_get s.ms_heap) unfold let eval_stack (ptr:int) (s:machine_stack) : nat64 = let Machine_stack _ mem = s in get_heap_val64 ptr mem unfold let eval_stack128 (ptr:int) (s:machine_stack) : quad32 = let Machine_stack _ mem = s in get_heap_val128 ptr mem (* Check if the taint annotation of a memory operand matches the taint in the memory map. Evaluation will fail in case of a mismatch. This allows the taint analysis to learn information about the memory map from the annotation, assuming that the code has been verified not to fail. (Note that this only relates to memory maps, so non-memory operands need no annotation.) *) [@"opaque_to_smt"] let rec match_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (b:bool{b <==> (forall i.{:pattern (memTaint `Map.sel` i)} (i >= addr /\ i < addr + n) ==> memTaint.[i] == t)}) (decreases n) = if n = 0 then true else if memTaint.[addr] <> t then false else match_n (addr + 1) (n - 1) memTaint t [@"opaque_to_smt"] let rec update_n (addr:int) (n:nat) (memTaint:memTaint_t) (t:taint) : Tot (m:memTaint_t{( forall i.{:pattern (m `Map.sel` i)} ((i >= addr /\ i < addr + n) ==> m.[i] == t) /\ ((i < addr \/ i >= addr + n) ==> m.[i] == memTaint.[i]))}) (decreases n) = if n = 0 then memTaint else update_n (addr + 1) (n - 1) (memTaint.[addr] <- t) t let lemma_is_machine_heap_update64 (ptr:int) (v:nat64) (mh:machine_heap) : Lemma (requires valid_addr64 ptr mh) (ensures is_machine_heap_update mh (update_heap64 ptr v mh)) [SMTPat (is_machine_heap_update mh (update_heap64 ptr v mh))] = reveal_opaque (`%valid_addr64) valid_addr64; update_heap64_reveal (); ()
{ "checked_file": "/", "dependencies": [ "Vale.SHA2.Wrapper.fsti.checked", "Vale.PPC64LE.Machine_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Lib.Set.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.Sel.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.MachineHeap_s.fst.checked", "Vale.Arch.HeapTypes_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked" ], "interface_file": false, "source_file": "Vale.PPC64LE.Semantics_s.fst" }
[ { "abbrev": false, "full_module": "Vale.SHA2.Wrapper", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Sel", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Heap", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapTypes_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.MachineHeap_s", "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.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ptr: Prims.int -> v: Vale.Def.Types_s.nat64 -> s: Vale.PPC64LE.Machine_s.state -> t: Vale.Arch.HeapTypes_s.taint -> Vale.PPC64LE.Machine_s.state
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Vale.Def.Types_s.nat64", "Vale.PPC64LE.Machine_s.state", "Vale.Arch.HeapTypes_s.taint", "Vale.Arch.MachineHeap_s.valid_addr64", "Vale.Arch.Heap.heap_get", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__cr0", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.Arch.Heap.heap_upd", "Vale.Arch.MachineHeap_s.update_heap64", "Vale.PPC64LE.Semantics_s.update_n", "Vale.Arch.Heap.heap_taint", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.bool" ]
[]
false
false
false
true
false
let update_mem_and_taint (ptr: int) (v: nat64) (s: state) (t: taint) : state =
if valid_addr64 ptr (heap_get s.ms_heap) then { s with ms_heap = heap_upd s.ms_heap (update_heap64 ptr v (heap_get s.ms_heap)) (update_n ptr 8 (heap_taint s.ms_heap) t) } else s
false