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.LowStarSig.fst | Vale.AsLowStar.LowStarSig.create_initial_vale_state | val create_initial_vale_state
(#max_arity: nat)
(#arg_reg: IX64.arg_reg_relation max_arity)
(args: IX64.arg_list)
: IX64.state_builder_t max_arity args V.vale_state_with_inv | val create_initial_vale_state
(#max_arity: nat)
(#arg_reg: IX64.arg_reg_relation max_arity)
(args: IX64.arg_list)
: IX64.state_builder_t max_arity args V.vale_state_with_inv | let create_initial_vale_state
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
: IX64.state_builder_t max_arity args V.vale_state_with_inv =
fun h0 ->
let (t_state, mem) = IX64.create_initial_trusted_state max_arity arg_reg args h0 in
let open VS in
{ vs_ok = true;
vs_regs = Vale.X64.Regs.of_fun t_state.BS.ms_regs;
vs_flags = Vale.X64.Flags.of_fun IA.init_flags;
vs_heap = create_initial_vale_full_heap mem (heap_taint t_state.BS.ms_heap);
vs_stack = as_vale_stack t_state.BS.ms_stack;
vs_stackTaint = t_state.BS.ms_stackTaint;
} | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 274,
"start_col": 0,
"start_line": 260
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl
[@__reduce__]
let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
[@__reduce__]
let rec register_args (max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.Tot.length args = n}) : VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity then True // This arg is passed on the stack
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s)
[@__reduce__]
let rec stack_args (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
: VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
stack_args max_arity (n - 1) tl s /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ VS.eval_reg_64 MS.rRsp s
in
SI.valid_stack_slot64 ptr s.VS.vs_stack MS.Public s.VS.vs_stackTaint /\
SI.load_stack64 ptr s.VS.vs_stack == arg_as_nat64 hd s)
[@__reduce__]
let taint_hyp_arg (m:ME.vale_heap) (tm:MS.memTaint_t) (a:arg) =
let (| tag, x |) = a in
match tag with
| TD_Buffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_buffer #src #TUInt64 x)
m
tm
tnt
| TD_Buffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_buffer #src #TUInt128 x)
m
tm
tnt
| TD_ImmBuffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_immbuffer #src #TUInt64 x)
m
tm
tnt
| TD_ImmBuffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_immbuffer #src #TUInt128 x)
m
tm
tnt
| _ ->
True
[@__reduce__]
let taint_hyp (args:list arg) : VSig.sprop =
fun s0 -> BigOps.big_and' (taint_hyp_arg (ME.get_vale_heap s0.VS.vs_heap) (full_heap_taint s0.VS.vs_heap)) args
[@__reduce__]
let vale_pre_hyp
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(args:IX64.arg_list)
: VSig.sprop =
fun s0 ->
V.state_inv s0 /\
ME.is_initial_heap s0.VS.vs_heap.vf_layout s0.VS.vs_heap.vf_heap /\
ME.get_heaplet_id s0.VS.vs_heap.vf_heap == None /\
VSig.disjoint_or_eq args /\
VSig.readable args (ME.get_vale_heap s0.VS.vs_heap) /\
register_args max_arity arg_reg (List.length args) args s0 /\
stack_args max_arity (List.length args) args s0 /\
VS.eval_reg_64 MS.rRsp s0 == SI.init_rsp s0.VS.vs_stack /\
taint_hyp args s0
[@__reduce__]
let to_low_pre
(#max_arity:nat)
(#arg_reg:IX64.arg_reg_relation max_arity)
(pre:VSig.vale_pre_tl [])
(args:IX64.arg_list)
(hs_mem:mem_roots args)
: prop =
(forall (s0:V.va_state).
V.va_get_ok s0 /\
vale_pre_hyp #max_arity #arg_reg args s0 /\
mem_correspondence args hs_mem s0 ==>
elim_nil pre s0)
[@__reduce__]
let to_low_post
(post:VSig.vale_post_tl [])
(args:list arg)
(hs_mem0:mem_roots args)
(res:UInt64.t)
(hs_mem1:mem_roots args)
: prop =
let open V in
B.modifies (loc_modified_args args) hs_mem0 hs_mem1 /\
(exists
(s0:va_state)
(s1:va_state)
(f:va_fuel).
mem_correspondence args hs_mem0 s0 /\
mem_correspondence args hs_mem1 s1 /\
UInt64.v res == VS.eval_reg_64 MS.rRax s1 /\
elim_nil post s0 s1 f) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | args: Vale.Interop.X64.arg_list
-> Vale.Interop.X64.state_builder_t max_arity args Vale.X64.Decls.vale_state_with_inv | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Interop.X64.arg_reg_relation",
"Vale.Interop.X64.arg_list",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.mem_roots_p",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Interop.Heap_s.interop_heap",
"Vale.X64.State.Mkvale_state",
"Vale.X64.Regs.of_fun",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs",
"Vale.X64.Flags.of_fun",
"Vale.Interop.Assumptions.init_flags",
"Vale.X64.MemoryAdapters.create_initial_vale_full_heap",
"Vale.Arch.Heap.heap_taint",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap",
"Vale.X64.MemoryAdapters.as_vale_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint",
"Vale.X64.Decls.vale_state_with_inv",
"FStar.Pervasives.Native.tuple2",
"Vale.Interop.X64.create_initial_trusted_state",
"Vale.Interop.X64.state_builder_t"
] | [] | false | false | false | false | false | let create_initial_vale_state
(#max_arity: nat)
(#arg_reg: IX64.arg_reg_relation max_arity)
(args: IX64.arg_list)
: IX64.state_builder_t max_arity args V.vale_state_with_inv =
| fun h0 ->
let t_state, mem = IX64.create_initial_trusted_state max_arity arg_reg args h0 in
let open VS in
{
vs_ok = true;
vs_regs = Vale.X64.Regs.of_fun t_state.BS.ms_regs;
vs_flags = Vale.X64.Flags.of_fun IA.init_flags;
vs_heap = create_initial_vale_full_heap mem (heap_taint t_state.BS.ms_heap);
vs_stack = as_vale_stack t_state.BS.ms_stack;
vs_stackTaint = t_state.BS.ms_stackTaint
} | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.stack_args | val stack_args (max_arity n: nat) (args: list arg {List.Tot.length args = n}) : VSig.sprop | val stack_args (max_arity n: nat) (args: list arg {List.Tot.length args = n}) : VSig.sprop | let rec stack_args (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
: VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
stack_args max_arity (n - 1) tl s /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ VS.eval_reg_64 MS.rRsp s
in
SI.valid_stack_slot64 ptr s.VS.vs_stack MS.Public s.VS.vs_stackTaint /\
SI.load_stack64 ptr s.VS.vs_stack == arg_as_nat64 hd s) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 172,
"start_col": 0,
"start_line": 155
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl
[@__reduce__]
let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
[@__reduce__]
let rec register_args (max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.Tot.length args = n}) : VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity then True // This arg is passed on the stack
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
max_arity: Prims.nat ->
n: Prims.nat ->
args: Prims.list Vale.Interop.Base.arg {FStar.List.Tot.Base.length args = n}
-> Vale.AsLowStar.ValeSig.sprop | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.list",
"Vale.Interop.Base.arg",
"Prims.b2t",
"Prims.op_Equality",
"FStar.List.Tot.Base.length",
"Vale.X64.State.vale_state",
"Prims.l_True",
"Prims.prop",
"Prims.l_and",
"Vale.AsLowStar.LowStarSig.stack_args",
"Prims.op_Subtraction",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"Vale.X64.Stack_i.valid_stack_slot64",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.Arch.HeapTypes_s.Public",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"Prims.eq2",
"Vale.X64.Memory.nat64",
"Vale.X64.Stack_i.load_stack64",
"Vale.AsLowStar.LowStarSig.arg_as_nat64",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Interop.Assumptions.win",
"Vale.X64.State.eval_reg_64",
"Vale.X64.Machine_s.rRsp",
"Prims.logical",
"Vale.AsLowStar.ValeSig.sprop"
] | [
"recursion"
] | false | false | false | false | false | let rec stack_args (max_arity n: nat) (args: list arg {List.Tot.length args = n}) : VSig.sprop =
| match args with
| [] -> (fun s -> True)
| hd :: tl ->
fun s ->
stack_args max_arity (n - 1) tl s /\
(if n <= max_arity
then True
else
let ptr =
((n - max_arity) - 1) * 8 + (if IA.win then 32 else 0) + 8 + VS.eval_reg_64 MS.rRsp s
in
SI.valid_stack_slot64 ptr s.VS.vs_stack MS.Public s.VS.vs_stackTaint /\
SI.load_stack64 ptr s.VS.vs_stack == arg_as_nat64 hd s) | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.taint_hyp_arg | val taint_hyp_arg : m: Vale.X64.Memory.vale_heap -> tm: Vale.Arch.HeapTypes_s.memTaint_t -> a: Vale.Interop.Base.arg
-> Type0 | let taint_hyp_arg (m:ME.vale_heap) (tm:MS.memTaint_t) (a:arg) =
let (| tag, x |) = a in
match tag with
| TD_Buffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_buffer #src #TUInt64 x)
m
tm
tnt
| TD_Buffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_buffer #src #TUInt128 x)
m
tm
tnt
| TD_ImmBuffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_immbuffer #src #TUInt64 x)
m
tm
tnt
| TD_ImmBuffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_immbuffer #src #TUInt128 x)
m
tm
tnt
| _ ->
True | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 203,
"start_col": 0,
"start_line": 175
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl
[@__reduce__]
let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
[@__reduce__]
let rec register_args (max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.Tot.length args = n}) : VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity then True // This arg is passed on the stack
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s)
[@__reduce__]
let rec stack_args (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
: VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
stack_args max_arity (n - 1) tl s /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ VS.eval_reg_64 MS.rRsp s
in
SI.valid_stack_slot64 ptr s.VS.vs_stack MS.Public s.VS.vs_stackTaint /\
SI.load_stack64 ptr s.VS.vs_stack == arg_as_nat64 hd s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Vale.X64.Memory.vale_heap -> tm: Vale.Arch.HeapTypes_s.memTaint_t -> a: Vale.Interop.Base.arg
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Memory.vale_heap",
"Vale.Arch.HeapTypes_s.memTaint_t",
"Vale.Interop.Base.arg",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Arch.HeapTypes_s.base_typ",
"Prims.bool",
"Vale.Arch.HeapTypes_s.taint",
"Vale.X64.Memory.valid_taint_buf64",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.X64.Memory.valid_taint_buf128",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.MemoryAdapters.as_vale_immbuffer",
"Prims.l_True"
] | [] | false | false | false | true | true | let taint_hyp_arg (m: ME.vale_heap) (tm: MS.memTaint_t) (a: arg) =
| let (| tag , x |) = a in
match tag with
| TD_Buffer src TUInt64 { taint = tnt } ->
ME.valid_taint_buf64 (as_vale_buffer #src #TUInt64 x) m tm tnt
| TD_Buffer src TUInt128 { taint = tnt } ->
ME.valid_taint_buf128 (as_vale_buffer #src #TUInt128 x) m tm tnt
| TD_ImmBuffer src TUInt64 { taint = tnt } ->
ME.valid_taint_buf64 (as_vale_immbuffer #src #TUInt64 x) m tm tnt
| TD_ImmBuffer src TUInt128 { taint = tnt } ->
ME.valid_taint_buf128 (as_vale_immbuffer #src #TUInt128 x) m tm tnt
| _ -> True | false |
|
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.register_args | val register_args
(max_arity: nat)
(arg_reg: IX64.arg_reg_relation max_arity)
(n: nat)
(args: list arg {List.Tot.length args = n})
: VSig.sprop | val register_args
(max_arity: nat)
(arg_reg: IX64.arg_reg_relation max_arity)
(n: nat)
(args: list arg {List.Tot.length args = n})
: VSig.sprop | let rec register_args (max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.Tot.length args = n}) : VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity then True // This arg is passed on the stack
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 152,
"start_col": 0,
"start_line": 142
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl
[@__reduce__]
let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
max_arity: Prims.nat ->
arg_reg: Vale.Interop.X64.arg_reg_relation max_arity ->
n: Prims.nat ->
args: Prims.list Vale.Interop.Base.arg {FStar.List.Tot.Base.length args = n}
-> Vale.AsLowStar.ValeSig.sprop | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Vale.Interop.X64.arg_reg_relation",
"Prims.list",
"Vale.Interop.Base.arg",
"Prims.b2t",
"Prims.op_Equality",
"FStar.List.Tot.Base.length",
"Vale.X64.State.vale_state",
"Prims.l_True",
"Prims.prop",
"Prims.l_and",
"Vale.AsLowStar.LowStarSig.register_args",
"Prims.op_Subtraction",
"Prims.op_GreaterThan",
"Prims.bool",
"Prims.eq2",
"Vale.X64.Memory.nat64",
"Vale.X64.State.eval_reg_64",
"Vale.Interop.X64.__proj__Rel__item__of_arg",
"Vale.AsLowStar.LowStarSig.arg_as_nat64",
"Prims.logical",
"Vale.AsLowStar.ValeSig.sprop"
] | [
"recursion"
] | false | false | false | false | false | let rec register_args
(max_arity: nat)
(arg_reg: IX64.arg_reg_relation max_arity)
(n: nat)
(args: list arg {List.Tot.length args = n})
: VSig.sprop =
| match args with
| [] -> (fun s -> True)
| hd :: tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity
then True
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s) | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.taint_hyp | val taint_hyp (args: list arg) : VSig.sprop | val taint_hyp (args: list arg) : VSig.sprop | let taint_hyp (args:list arg) : VSig.sprop =
fun s0 -> BigOps.big_and' (taint_hyp_arg (ME.get_vale_heap s0.VS.vs_heap) (full_heap_taint s0.VS.vs_heap)) args | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 113,
"end_line": 207,
"start_col": 0,
"start_line": 206
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl
[@__reduce__]
let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
[@__reduce__]
let rec register_args (max_arity:nat)
(arg_reg:IX64.arg_reg_relation max_arity)
(n:nat)
(args:list arg{List.Tot.length args = n}) : VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
register_args max_arity arg_reg (n - 1) tl s /\
(if n > max_arity then True // This arg is passed on the stack
else VS.eval_reg_64 (arg_reg.IX64.of_arg (n - 1)) s == arg_as_nat64 hd s)
[@__reduce__]
let rec stack_args (max_arity:nat)
(n:nat)
(args:list arg{List.Tot.length args = n})
: VSig.sprop =
match args with
| [] -> (fun s -> True)
| hd::tl ->
fun s ->
stack_args max_arity (n - 1) tl s /\
(if n <= max_arity then True // This arg is passed in registers
else
let ptr = ((n - max_arity) - 1) * 8
+ (if IA.win then 32 else 0)
+ 8
+ VS.eval_reg_64 MS.rRsp s
in
SI.valid_stack_slot64 ptr s.VS.vs_stack MS.Public s.VS.vs_stackTaint /\
SI.load_stack64 ptr s.VS.vs_stack == arg_as_nat64 hd s)
[@__reduce__]
let taint_hyp_arg (m:ME.vale_heap) (tm:MS.memTaint_t) (a:arg) =
let (| tag, x |) = a in
match tag with
| TD_Buffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_buffer #src #TUInt64 x)
m
tm
tnt
| TD_Buffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_buffer #src #TUInt128 x)
m
tm
tnt
| TD_ImmBuffer src TUInt64 {taint=tnt} ->
ME.valid_taint_buf64
(as_vale_immbuffer #src #TUInt64 x)
m
tm
tnt
| TD_ImmBuffer src TUInt128 {taint=tnt} ->
ME.valid_taint_buf128
(as_vale_immbuffer #src #TUInt128 x)
m
tm
tnt
| _ ->
True | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | args: Prims.list Vale.Interop.Base.arg -> Vale.AsLowStar.ValeSig.sprop | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.X64.State.vale_state",
"FStar.BigOps.big_and'",
"Vale.AsLowStar.LowStarSig.taint_hyp_arg",
"Vale.X64.Memory.get_vale_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.Arch.HeapImpl.full_heap_taint",
"Prims.prop",
"Vale.AsLowStar.ValeSig.sprop"
] | [] | false | false | false | true | false | let taint_hyp (args: list arg) : VSig.sprop =
| fun s0 ->
BigOps.big_and' (taint_hyp_arg (ME.get_vale_heap s0.VS.vs_heap) (full_heap_taint s0.VS.vs_heap))
args | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.mem_correspondence | val mem_correspondence (args: list arg) : hsprop | val mem_correspondence (args: list arg) : hsprop | let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 118,
"start_col": 0,
"start_line": 103
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | args: Prims.list Vale.Interop.Base.arg -> Vale.AsLowStar.LowStarSig.hsprop | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.Interop.Base.arg",
"FStar.Monotonic.HyperStack.mem",
"Vale.X64.State.vale_state",
"Prims.l_True",
"Prims.prop",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Prims.l_and",
"Vale.AsLowStar.LowStarSig.mem_correspondence_1",
"Vale.AsLowStar.LowStarSig.mem_correspondence",
"Vale.AsLowStar.LowStarSig.mem_imm_correspondence_1",
"Vale.Interop.Base.valid_base_type",
"Vale.AsLowStar.LowStarSig.hsprop"
] | [
"recursion"
] | false | false | false | true | false | let rec mem_correspondence (args: list arg) : hsprop =
| match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag , x |) = hd in
match tag with
| TD_Buffer src bt _ -> fun h s -> mem_correspondence_1 src bt x h s /\ mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s -> mem_imm_correspondence_1 src bt x h s /\ mem_correspondence tl h s
| TD_Base _ -> mem_correspondence tl | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.uint_to_nat | val uint_to_nat (t: ME.base_typ) (x: base_typ_as_type t) : ME.base_typ_as_vale_type t | val uint_to_nat (t: ME.base_typ) (x: base_typ_as_type t) : ME.base_typ_as_vale_type t | let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 41,
"start_col": 0,
"start_line": 33
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.Arch.HeapTypes_s.base_typ -> x: Vale.Interop.Types.base_typ_as_type t
-> Vale.X64.Memory.base_typ_as_vale_type t | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Types.base_typ_as_type",
"FStar.UInt8.v",
"FStar.UInt16.v",
"FStar.UInt32.v",
"FStar.UInt64.v",
"Vale.X64.Memory.base_typ_as_vale_type"
] | [] | false | false | false | false | false | let uint_to_nat (t: ME.base_typ) (x: base_typ_as_type t) : ME.base_typ_as_vale_type t =
| let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x | false |
Hacl.Impl.RSAPSS.Keys.fst | Hacl.Impl.RSAPSS.Keys.new_rsapss_load_skey | val new_rsapss_load_skey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t ->
new_rsapss_load_skey_st t ke modBits | val new_rsapss_load_skey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t ->
new_rsapss_load_skey_st t ke modBits | let new_rsapss_load_skey #t ke modBits kc r eBits dBits nb eb db =
[@inline_let] let bits = size (bits t) in
if not (rsapss_check_skey_len #t modBits eBits dBits) then
B.null
else begin
assert (LS.skey_len_pre t (v modBits) (v eBits) (v dBits));
let h0 = ST.get () in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let dLen = blocks dBits bits in
let skeyLen = nLen +! nLen +! eLen +! dLen in
let skey = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) skeyLen in
if B.is_null skey then
skey
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len skey == skeyLen);
let skey: Lib.Buffer.buffer (limb t) = skey in
assert (B.length skey == FStar.UInt32.v skeyLen);
let skey: lbignum t skeyLen = skey in
let b = rsapss_load_skey ke modBits kc (rsapss_load_pkey ke modBits kc) eBits dBits nb eb db skey in
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
LS.rsapss_load_skey_lemma #t (v modBits) (v eBits) (v dBits)
(as_seq h0 nb) (as_seq h0 eb) (as_seq h0 db);
if b then skey else begin
B.free (skey <: buffer (limb t));
B.null end
end | {
"file_name": "code/rsapss/Hacl.Impl.RSAPSS.Keys.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 436,
"start_col": 0,
"start_line": 406
} | module Hacl.Impl.RSAPSS.Keys
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module LS = Hacl.Spec.RSAPSS
module BM = Hacl.Bignum.Montgomery
module BN = Hacl.Bignum
module BB = Hacl.Spec.Bignum.Base
module BE = Hacl.Bignum.Exponentiation
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val rsapss_check_pkey_len:
#t:limb_t
-> modBits:size_t
-> eBits:size_t ->
res:bool{res <==> LS.pkey_len_pre t (v modBits) (v eBits)}
let rsapss_check_pkey_len #t modBits eBits =
if 1ul <. modBits && 0ul <. eBits then begin
[@inline_let] let bits = size (bits t) in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
nLen <=. 0xfffffffful /. (2ul *! bits) && eLen <=. 0xfffffffful /. bits &&
nLen +! nLen <=. 0xfffffffful -. eLen end
else false
inline_for_extraction noextract
val rsapss_check_skey_len:
#t:limb_t
-> modBits:size_t
-> eBits:size_t
-> dBits:size_t ->
res:bool{res <==> LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}
let rsapss_check_skey_len #t modBits eBits dBits =
if rsapss_check_pkey_len #t modBits eBits && 0ul <. dBits then begin
[@inline_let] let bits = size (bits t) in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let dLen = blocks dBits bits in
dLen <=. 0xfffffffful /. bits &&
2ul *! nLen <=. 0xfffffffful -! eLen -! dLen end
else false
inline_for_extraction noextract
let bn_check_num_bits_st (t:limb_t) =
bs:size_t{0 < v bs /\ bits t * v (blocks bs (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks bs (size (bits t))) ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == LS.bn_check_num_bits (v bs) (as_seq h0 b))
inline_for_extraction noextract
val bn_check_num_bits: #t:limb_t -> bn_check_num_bits_st t
let bn_check_num_bits #t bs b =
[@inline_let] let bits = size (bits t) in
let bLen = blocks bs bits in
if bs =. bits *! bLen then ones t SEC else BN.bn_lt_pow2_mask bLen b bs
inline_for_extraction noextract
let rsapss_check_modulus_st (t:limb_t) =
modBits:size_t{0 < v modBits /\ bits t * v (blocks modBits (size (bits t))) <= max_size_t}
-> n:lbignum t (blocks modBits (size (bits t))) ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == LS.rsapss_check_modulus (v modBits) (as_seq h0 n))
inline_for_extraction noextract
val rsapss_check_modulus:
#t:limb_t
-> bn_check_num_bits:bn_check_num_bits_st t ->
rsapss_check_modulus_st t
let rsapss_check_modulus #t bn_check_num_bits modBits n =
let nLen = blocks modBits (size (bits t)) in
let bits0 = BN.bn_is_odd nLen n in
let m0 = uint #t 0 -. bits0 in
let m1 = BN.bn_gt_pow2_mask nLen n (modBits -! 1ul) in
let m2 = bn_check_num_bits modBits n in
m0 &. (m1 &. m2)
inline_for_extraction noextract
let rsapss_check_exponent_st (t:limb_t) =
eBits:size_t{0 < v eBits /\ bits t * v (blocks eBits (size (bits t))) <= max_size_t}
-> e:lbignum t (blocks eBits (size (bits t))) ->
Stack (limb t)
(requires fun h -> live h e)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == LS.rsapss_check_exponent (v eBits) (as_seq h0 e))
inline_for_extraction noextract
val rsapss_check_exponent:
#t:limb_t
-> bn_check_num_bits:bn_check_num_bits_st t ->
rsapss_check_exponent_st t
let rsapss_check_exponent #t bn_check_num_bits eBits e =
let eLen = blocks eBits (size (bits t)) in
let m0 = BN.bn_is_zero_mask eLen e in
let m1 = bn_check_num_bits eBits e in
(lognot m0) &. m1
inline_for_extraction noextract
class rsapss_checks (t:limb_t) = {
check_num_bits: bn_check_num_bits_st t;
check_modulus: rsapss_check_modulus_st t;
check_exponent: rsapss_check_exponent_st t;
}
[@CInline]
let check_num_bits_u32 : bn_check_num_bits_st U32 =
bn_check_num_bits
[@CInline]
let check_modulus_u32 : rsapss_check_modulus_st U32 =
rsapss_check_modulus check_num_bits_u32
[@CInline]
let check_exponent_u32 : rsapss_check_exponent_st U32 =
rsapss_check_exponent check_num_bits_u32
inline_for_extraction noextract
val mk_runtime_rsapss_checks_uint32: rsapss_checks U32
let mk_runtime_rsapss_checks_uint32 = {
check_num_bits = check_num_bits_u32;
check_modulus = check_modulus_u32;
check_exponent = check_exponent_u32;
}
[@CInline]
let check_num_bits_u64 : bn_check_num_bits_st U64 =
bn_check_num_bits
[@CInline]
let check_modulus_u64 : rsapss_check_modulus_st U64 =
rsapss_check_modulus check_num_bits_u64
[@CInline]
let check_exponent_u64 : rsapss_check_exponent_st U64 =
rsapss_check_exponent check_num_bits_u64
inline_for_extraction noextract
val mk_runtime_rsapss_checks_uint64: rsapss_checks U64
let mk_runtime_rsapss_checks_uint64 = {
check_num_bits = check_num_bits_u64;
check_modulus = check_modulus_u64;
check_exponent = check_exponent_u64;
}
inline_for_extraction noextract
let mk_runtime_rsapss_checks (#t:limb_t) : rsapss_checks t =
match t with
| U32 -> mk_runtime_rsapss_checks_uint32
| U64 -> mk_runtime_rsapss_checks_uint64
//pkey = [n; r2; e]
inline_for_extraction noextract
let rsapss_load_pkey_st (t:limb_t) (ke:BE.exp t) (modBits:size_t) =
eBits:size_t{LS.pkey_len_pre t (v modBits) (v eBits)}
-> nb:lbuffer uint8 (blocks modBits 8ul)
-> eb:lbuffer uint8 (blocks eBits 8ul)
-> pkey:lbignum t (2ul *! blocks modBits (size (bits t)) +! blocks eBits (size (bits t))) ->
Stack bool
(requires fun h ->
blocks modBits (size (bits t)) == ke.BE.bn.BN.len /\
live h nb /\ live h eb /\ live h pkey /\
disjoint pkey nb /\ disjoint pkey eb)
(ensures fun h0 b h1 -> modifies (loc pkey) h0 h1 /\
(b, as_seq h1 pkey) == LS.rsapss_load_pkey (v modBits) (v eBits) (as_seq h0 nb) (as_seq h0 eb))
inline_for_extraction noextract
val rsapss_load_pkey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t ->
rsapss_load_pkey_st t ke modBits
let rsapss_load_pkey #t ke modBits kc eBits nb eb pkey =
let h0 = ST.get () in
[@inline_let] let bits = size (bits t) in
[@inline_let] let numb = size (numbytes t) in
let nbLen = blocks modBits 8ul in
let ebLen = blocks eBits 8ul in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
assert (v ((modBits -! 1ul) /. bits) < v nLen);
LS.blocks_bits_lemma t (v modBits);
assert (v (blocks nbLen numb) == v nLen);
LS.blocks_bits_lemma t (v eBits);
assert (v (blocks ebLen numb) == v eLen);
let n = sub pkey 0ul nLen in
let r2 = sub pkey nLen nLen in
let e = sub pkey (nLen +! nLen) eLen in
BN.bn_from_bytes_be nbLen nb n;
ke.BE.precompr2 (modBits -! 1ul) n r2;
BN.bn_from_bytes_be ebLen eb e;
let h1 = ST.get () in
LSeq.lemma_concat3 (v nLen) (as_seq h1 n)
(v nLen) (as_seq h1 r2) (v eLen) (as_seq h1 e) (as_seq h1 pkey);
let m0 = kc.check_modulus modBits n in
let m1 = kc.check_exponent eBits e in
let m = m0 &. m1 in
BB.unsafe_bool_of_limb #t m
#set-options "--z3rlimit 300"
//skey = [pkey; d]
inline_for_extraction noextract
let rsapss_load_skey_st (t:limb_t) (ke:BE.exp t) (modBits:size_t) =
eBits:size_t
-> dBits:size_t{LS.skey_len_pre t (v modBits) (v eBits) (v dBits)}
-> nb:lbuffer uint8 (blocks modBits 8ul)
-> eb:lbuffer uint8 (blocks eBits 8ul)
-> db:lbuffer uint8 (blocks dBits 8ul)
-> skey:lbignum t (2ul *! blocks modBits (size (bits t)) +! blocks eBits (size (bits t)) +! blocks dBits (size (bits t))) ->
Stack bool
(requires fun h ->
blocks modBits (size (bits t)) == ke.BE.bn.BN.len /\
live h nb /\ live h eb /\ live h db /\ live h skey /\
disjoint skey nb /\ disjoint skey eb /\ disjoint skey db)
(ensures fun h0 b h1 -> modifies (loc skey) h0 h1 /\
(b, as_seq h1 skey) == LS.rsapss_load_skey (v modBits) (v eBits) (v dBits)
(as_seq h0 nb) (as_seq h0 eb) (as_seq h0 db))
inline_for_extraction noextract
val rsapss_load_skey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t
-> rsapss_load_pkey:rsapss_load_pkey_st t ke modBits ->
rsapss_load_skey_st t ke modBits
let rsapss_load_skey #t ke modBits kc rsapss_load_pkey eBits dBits nb eb db skey =
let h0 = ST.get () in
[@inline_let] let bits = size (bits t) in
[@inline_let] let numb = size (numbytes t) in
let nbLen = blocks modBits 8ul in
let ebLen = blocks eBits 8ul in
let dbLen = blocks dBits 8ul in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let dLen = blocks dBits bits in
let pkeyLen = nLen +! nLen +! eLen in
let skeyLen = pkeyLen +! eLen in
LS.blocks_bits_lemma t (v dBits);
assert (v (blocks dbLen numb) == v dLen);
let pkey = sub skey 0ul pkeyLen in
let d = sub skey pkeyLen dLen in
let b = rsapss_load_pkey eBits nb eb pkey in
BN.bn_from_bytes_be dbLen db d;
let h1 = ST.get () in
LSeq.lemma_concat2 (v pkeyLen) (as_seq h1 pkey) (v dLen) (as_seq h1 d) (as_seq h1 skey);
let m1 = kc.check_exponent dBits d in
let b1 = b && BB.unsafe_bool_of_limb m1 in
b1
inline_for_extraction noextract
let new_rsapss_load_pkey_st (t:limb_t) (ke:BE.exp t) (modBits:size_t) =
r:HS.rid
-> eBits:size_t
-> nb:lbuffer uint8 (blocks0 modBits 8ul)
-> eb:lbuffer uint8 (blocks0 eBits 8ul) ->
ST (B.buffer (limb t))
(requires fun h ->
blocks0 modBits (size (bits t)) == ke.BE.bn.BN.len /\
live h nb /\ live h eb /\ ST.is_eternal_region r)
(ensures fun h0 pkey h1 -> B.(modifies loc_none h0 h1) /\
not (B.g_is_null pkey) ==> (
LS.pkey_len_pre t (v modBits) (v eBits) /\
B.(fresh_loc (loc_buffer pkey) h0 h1) /\
B.freeable pkey /\
B.(loc_includes (loc_region_only false r) (loc_buffer pkey)) /\
(let bits = size (bits t) in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let pkeyLen = nLen +! nLen +! eLen in
B.len pkey == pkeyLen /\
(let pkey = pkey <: lbignum t pkeyLen in
LS.rsapss_load_pkey_post (v modBits) (v eBits)
(as_seq h0 nb) (as_seq h0 eb) (as_seq h1 pkey)))))
inline_for_extraction noextract
val new_rsapss_load_pkey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t ->
new_rsapss_load_pkey_st t ke modBits
let new_rsapss_load_pkey #t ke modBits kc r eBits nb eb =
[@inline_let] let bits = size (bits t) in
if not (rsapss_check_pkey_len #t modBits eBits) then
B.null
else
let h0 = ST.get () in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let pkeyLen = nLen +! nLen +! eLen in
let pkey = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) pkeyLen in
if B.is_null pkey then
pkey
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len pkey == pkeyLen);
let pkey: Lib.Buffer.buffer (limb t) = pkey in
assert (B.length pkey == FStar.UInt32.v pkeyLen);
let pkey: lbignum t pkeyLen = pkey in
let b = rsapss_load_pkey ke modBits kc eBits nb eb pkey in
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
LS.rsapss_load_pkey_lemma #t (v modBits) (v eBits) (as_seq h0 nb) (as_seq h0 eb);
if b then pkey else begin
B.free (pkey <: buffer (limb t));
B.null end
inline_for_extraction noextract
let new_rsapss_load_skey_st (t:limb_t) (ke:BE.exp t) (modBits:size_t) =
r:HS.rid
-> eBits:size_t
-> dBits:size_t
-> nb:lbuffer uint8 (blocks0 modBits 8ul)
-> eb:lbuffer uint8 (blocks0 eBits 8ul)
-> db:lbuffer uint8 (blocks0 dBits 8ul) ->
ST (B.buffer (limb t))
(requires fun h ->
blocks0 modBits (size (bits t)) == ke.BE.bn.BN.len /\
live h nb /\ live h eb /\ live h db /\
ST.is_eternal_region r)
(ensures fun h0 skey h1 -> B.(modifies loc_none h0 h1) /\
not (B.g_is_null skey) ==> (
LS.skey_len_pre t (v modBits) (v eBits) (v dBits) /\
B.(fresh_loc (loc_buffer skey) h0 h1) /\
B.freeable skey /\
B.(loc_includes (loc_region_only false r) (loc_buffer skey)) /\
(let bits = size (bits t) in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let dLen = blocks dBits bits in
let skeyLen = nLen +! nLen +! eLen +! dLen in
B.len skey == skeyLen /\
(let skey = skey <: lbignum t skeyLen in
LS.rsapss_load_skey_post (v modBits) (v eBits) (v dBits)
(as_seq h0 nb) (as_seq h0 eb) (as_seq h0 db) (as_seq h1 skey)))))
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val new_rsapss_load_skey:
#t:limb_t
-> ke:BE.exp t
-> modBits:size_t
-> kc:rsapss_checks t ->
new_rsapss_load_skey_st t ke modBits | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.RSAPSS.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.RSAPSS.Keys.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.RSAPSS",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.RSAPSS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ke: Hacl.Bignum.Exponentiation.exp t ->
modBits: Lib.IntTypes.size_t ->
kc: Hacl.Impl.RSAPSS.Keys.rsapss_checks t
-> Hacl.Impl.RSAPSS.Keys.new_rsapss_load_skey_st t ke modBits | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Exponentiation.exp",
"Lib.IntTypes.size_t",
"Hacl.Impl.RSAPSS.Keys.rsapss_checks",
"FStar.Monotonic.HyperHeap.rid",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Bignum.Definitions.blocks0",
"FStar.UInt32.__uint_to_t",
"Prims.op_Negation",
"Hacl.Impl.RSAPSS.Keys.rsapss_check_skey_len",
"LowStar.Buffer.null",
"Hacl.Bignum.Definitions.limb",
"LowStar.Buffer.buffer",
"Prims.bool",
"Prims.unit",
"LowStar.Monotonic.Buffer.free",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"Hacl.Spec.RSAPSS.rsapss_load_skey_lemma",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.RSAPSS.Keys.rsapss_load_skey",
"Hacl.Impl.RSAPSS.Keys.rsapss_load_pkey",
"Hacl.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"Lib.Buffer.buffer_t",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.is_null",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.g_is_null",
"Prims.l_and",
"Prims.nat",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Monotonic.Buffer.mmalloc_partial",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"LowStar.Monotonic.Buffer.lmbuffer_or_null",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_Multiply",
"Hacl.Spec.Bignum.Definitions.blocks",
"Hacl.Bignum.Definitions.blocks",
"Hacl.Spec.RSAPSS.skey_len_pre",
"Lib.IntTypes.size",
"Lib.IntTypes.bits"
] | [] | false | false | false | false | false | let new_rsapss_load_skey #t ke modBits kc r eBits dBits nb eb db =
| [@@ inline_let ]let bits = size (bits t) in
if not (rsapss_check_skey_len #t modBits eBits dBits)
then B.null
else
(assert (LS.skey_len_pre t (v modBits) (v eBits) (v dBits));
let h0 = ST.get () in
let nLen = blocks modBits bits in
let eLen = blocks eBits bits in
let dLen = blocks dBits bits in
let skeyLen = nLen +! nLen +! eLen +! dLen in
let skey = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) skeyLen in
if B.is_null skey
then skey
else
let h1 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h1);
assert (B.len skey == skeyLen);
let skey:Lib.Buffer.buffer (limb t) = skey in
assert (B.length skey == FStar.UInt32.v skeyLen);
let skey:lbignum t skeyLen = skey in
let b =
rsapss_load_skey ke modBits kc (rsapss_load_pkey ke modBits kc) eBits dBits nb eb db skey
in
let h2 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h2);
LS.rsapss_load_skey_lemma #t
(v modBits)
(v eBits)
(v dBits)
(as_seq h0 nb)
(as_seq h0 eb)
(as_seq h0 db);
if b
then skey
else
(B.free (skey <: buffer (limb t));
B.null)) | false |
Vale.AsLowStar.LowStarSig.fst | Vale.AsLowStar.LowStarSig.arg_as_nat64 | val arg_as_nat64 (a: arg) (s: VS.vale_state) : GTot ME.nat64 | val arg_as_nat64 (a: arg) (s: VS.vale_state) : GTot ME.nat64 | let arg_as_nat64 (a:arg) (s:VS.vale_state) : GTot ME.nat64 =
let (| tag, x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 ->
UInt8.v x
| TD_Base TUInt16 ->
UInt16.v x
| TD_Base TUInt32 ->
UInt32.v x
| TD_Base TUInt64 ->
UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.LowStarSig.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 138,
"start_col": 0,
"start_line": 121
} | module Vale.AsLowStar.LowStarSig
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module BS = Vale.X64.Machine_Semantics_s
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module HS = FStar.HyperStack
module ME = Vale.X64.Memory
module SI = Vale.X64.Stack_i
module MS = Vale.X64.Machine_s
module IA = Vale.Interop.Assumptions
module V = Vale.X64.Decls
module VS = Vale.X64.State
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module Map16 = Vale.Lib.Map16
open FStar.Mul
[@__reduce__]
let nat_to_uint (t:ME.base_typ) (x:ME.base_typ_as_vale_type t)
: base_typ_as_type t
= let open ME in
match t with
| TUInt8 -> UInt8.uint_to_t x
| TUInt16 -> UInt16.uint_to_t x
| TUInt32 -> UInt32.uint_to_t x
| TUInt64 -> UInt64.uint_to_t x
| TUInt128 -> x
let uint_to_nat (t:ME.base_typ) (x:base_typ_as_type t)
: ME.base_typ_as_vale_type t
= let open ME in
match t with
| TUInt8 -> UInt8.v x
| TUInt16 -> UInt16.v x
| TUInt32 -> UInt32.v x
| TUInt64 -> UInt64.v x
| TUInt128 -> x
let nat_to_uint_seq_t
(t:ME.base_typ)
(b:Seq.seq (ME.base_typ_as_vale_type t))
: Seq.seq (base_typ_as_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> nat_to_uint t (Seq.index b i))
let uint_to_nat_seq_t
(t:ME.base_typ)
(b:Seq.seq (base_typ_as_type t))
: Seq.seq (ME.base_typ_as_vale_type t)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> uint_to_nat t (Seq.index b i))
[@__reduce__]
let view_of_base_typ (t:ME.base_typ)
: UV.view UInt8.t (base_typ_as_type t)
= let open ME in
match t with
| TUInt8 -> Vale.Interop.Views.up_view8
| TUInt16 -> Vale.Interop.Views.up_view16
| TUInt32 -> Vale.Interop.Views.up_view32
| TUInt64 -> Vale.Interop.Views.up_view64
| TUInt128 -> Vale.Interop.Views.up_view128
//////////////////////////////////////////////////////////////////////////////////////////
//lowstar_sig pre post:
// Interepreting a vale pre/post as a Low* function type
//////////////////////////////////////////////////////////////////////////////////////////
let hprop = HS.mem -> prop
let hsprop = HS.mem -> VS.vale_state -> prop
module IB = Vale.Interop.Base
[@__reduce__]
let mem_correspondence_1
(src t:ME.base_typ)
(x:IB.buf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let mem_imm_correspondence_1
(src t:ME.base_typ)
(x:IB.ibuf_t src t)
(h:HS.mem)
(s:VS.vale_state) =
let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
Seq.equal
(nat_to_uint_seq_t t (ME.buffer_as_seq (ME.get_vale_heap s.VS.vs_heap) y))
(UV.as_seq h (UV.mk_buffer db (view_of_base_typ t)))
[@__reduce__]
let rec mem_correspondence (args:list arg) : hsprop =
match args with
| [] -> fun h s -> True
| hd :: tl ->
let (| tag, x |) = hd in
match tag with
| TD_Buffer src bt _ ->
fun h s ->
mem_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_ImmBuffer src bt _ ->
fun h s ->
mem_imm_correspondence_1 src bt x h s /\
mem_correspondence tl h s
| TD_Base _ ->
mem_correspondence tl | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Lib.Map16.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.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.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AsLowStar.LowStarSig.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"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_i",
"short_module": "SI"
},
{
"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.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"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.Arch.HeapImpl",
"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": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Vale.Interop.Base.arg -> s: Vale.X64.State.vale_state -> Prims.GTot Vale.X64.Memory.nat64 | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Interop.Base.arg",
"Vale.X64.State.vale_state",
"Vale.Interop.Base.td",
"Vale.Interop.Base.td_as_type",
"FStar.UInt8.v",
"FStar.UInt16.v",
"FStar.UInt32.v",
"FStar.UInt64.v",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buffer_qualifiers",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.X64.Memory.get_vale_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Prims.unit",
"Vale.X64.MemoryAdapters.buffer_addr_is_nat64",
"Vale.X64.MemoryAdapters.as_vale_immbuffer",
"Vale.X64.Memory.nat64"
] | [] | false | false | false | false | false | let arg_as_nat64 (a: arg) (s: VS.vale_state) : GTot ME.nat64 =
| let (| tag , x |) = a in
let open ME in
match tag with
| TD_Base TUInt8 -> UInt8.v x
| TD_Base TUInt16 -> UInt16.v x
| TD_Base TUInt32 -> UInt32.v x
| TD_Base TUInt64 -> UInt64.v x
| TD_Buffer src bt _ ->
buffer_addr_is_nat64 (as_vale_buffer #src #bt x) s;
ME.buffer_addr (as_vale_buffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap)
| TD_ImmBuffer src bt _ ->
buffer_addr_is_nat64 (as_vale_immbuffer #src #bt x) s;
ME.buffer_addr (as_vale_immbuffer #src #bt x) (ME.get_vale_heap s.VS.vs_heap) | false |
OPLSS2021.NDS.fst | OPLSS2021.NDS.tape | val tape : Type0 | let tape = nat -> bool | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": 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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.bool"
] | [] | false | false | false | true | true | let tape =
| nat -> bool | false |
|
OPLSS2021.NDS.fst | OPLSS2021.NDS.return | val return (a: Type) (x: a) (s: _) : nds a s | val return (a: Type) (x: a) (s: _) : nds a s | let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 31,
"start_col": 0,
"start_line": 29
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a -> s: Type0 -> OPLSS2021.NDS.nds a s | Prims.Tot | [
"total"
] | [] | [
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.tuple3",
"OPLSS2021.NDS.nds"
] | [] | false | false | false | true | false | let return (a: Type) (x: a) s : nds a s =
| fun t n s -> x, s, n | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.uint8 | val uint8 : Type0 | let uint8 = Lib.IntTypes.uint8 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint8"
] | [] | false | false | false | true | true | let uint8 =
| Lib.IntTypes.uint8 | false |
|
OPLSS2021.NDS.fst | OPLSS2021.NDS.bind | val bind (a b s: _) (f: nds a s) (g: (a -> nds b s)) : nds b s | val bind (a b s: _) (f: nds a s) (g: (a -> nds b s)) : nds b s | let bind a b s (f:nds a s) (g:a -> nds b s)
: nds b s
= fun t n s ->
let x, s', n' = f t n s in
g x t n' s' | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 37,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat
let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> b: Type -> s: Type0 -> f: OPLSS2021.NDS.nds a s -> g: (_: a -> OPLSS2021.NDS.nds b s)
-> OPLSS2021.NDS.nds b s | Prims.Tot | [
"total"
] | [] | [
"OPLSS2021.NDS.nds",
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.tuple3"
] | [] | false | false | false | true | false | let bind a b s (f: nds a s) (g: (a -> nds b s)) : nds b s =
| fun t n s ->
let x, s', n' = f t n s in
g x t n' s' | false |
OPLSS2021.NDS.fst | OPLSS2021.NDS.put | val put (#s: _) (x: s) : NDS unit s | val put (#s: _) (x: s) : NDS unit s | let put #s (x:s)
: NDS unit s
= NDS?.reflect (fun t n _ -> (), x, n) | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 54,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat
let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n
let bind a b s (f:nds a s) (g:a -> nds b s)
: nds b s
= fun t n s ->
let x, s', n' = f t n s in
g x t n' s'
total
reflectable
effect {
NDS (a:Type) ([@@@ effect_param] st:Type0)
with {repr = nds; return; bind}
}
/// Reading the state
let get #s ()
: NDS s s
= NDS?.reflect (fun t n s -> s, s, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: s -> OPLSS2021.NDS.NDS Prims.unit | OPLSS2021.NDS.NDS | [] | [] | [
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple3",
"Prims.unit",
"FStar.Pervasives.Native.tuple3"
] | [] | false | true | false | false | false | let put #s (x: s) : NDS unit s =
| NDS?.reflect (fun t n _ -> (), x, n) | false |
OPLSS2021.NDS.fst | OPLSS2021.NDS.nds | val nds : a: Type -> s: Type0 -> Type | let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> s: Type0 -> Type | Prims.Tot | [
"total"
] | [] | [
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.tuple3"
] | [] | false | false | false | true | true | let nds (a: Type) (s: Type0) =
| tape -> nat -> s -> a & s & nat | false |
|
OPLSS2021.NDS.fst | OPLSS2021.NDS.get | val get: #s: _ -> Prims.unit -> NDS s s | val get: #s: _ -> Prims.unit -> NDS s s | let get #s ()
: NDS s s
= NDS?.reflect (fun t n s -> s, s, n) | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 49,
"start_col": 0,
"start_line": 47
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat
let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n
let bind a b s (f:nds a s) (g:a -> nds b s)
: nds b s
= fun t n s ->
let x, s', n' = f t n s in
g x t n' s'
total
reflectable
effect {
NDS (a:Type) ([@@@ effect_param] st:Type0)
with {repr = nds; return; bind}
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": 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 | _: Prims.unit -> OPLSS2021.NDS.NDS s | OPLSS2021.NDS.NDS | [] | [] | [
"Prims.unit",
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.tuple3"
] | [] | false | true | false | false | false | let get #s () : NDS s s =
| NDS?.reflect (fun t n s -> s, s, n) | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.uint32 | val uint32 : Type0 | let uint32 = Lib.IntTypes.uint32 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint32"
] | [] | false | false | false | true | true | let uint32 =
| Lib.IntTypes.uint32 | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.uint64 | val uint64 : Type0 | let uint64 = Lib.IntTypes.uint64 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint64"
] | [] | false | false | false | true | true | let uint64 =
| Lib.IntTypes.uint64 | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.alg | val alg : Type0 | let alg = keccak_alg | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function. | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.keccak_alg"
] | [] | false | false | false | true | true | let alg =
| keccak_alg | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.singleton | val singleton : x: t -> Type | let singleton #t (x: t) = y:t { y == x } | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 81,
"start_col": 0,
"start_line": 81
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | x: t -> Type | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2"
] | [] | false | false | false | true | true | let singleton #t (x: t) =
| y: t{y == x} | false |
|
OPLSS2021.NDS.fst | OPLSS2021.NDS.sample | val sample: #s: _ -> Prims.unit -> NDS bool s | val sample: #s: _ -> Prims.unit -> NDS bool s | let sample #s ()
: NDS bool s
= NDS?.reflect (fun t n s -> t n, s, n + 1) | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 59,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat
let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n
let bind a b s (f:nds a s) (g:a -> nds b s)
: nds b s
= fun t n s ->
let x, s', n' = f t n s in
g x t n' s'
total
reflectable
effect {
NDS (a:Type) ([@@@ effect_param] st:Type0)
with {repr = nds; return; bind}
}
/// Reading the state
let get #s ()
: NDS s s
= NDS?.reflect (fun t n s -> s, s, n)
/// Writing the state
let put #s (x:s)
: NDS unit s
= NDS?.reflect (fun t n _ -> (), x, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": 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 | _: Prims.unit -> OPLSS2021.NDS.NDS Prims.bool | OPLSS2021.NDS.NDS | [] | [] | [
"Prims.unit",
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple3",
"Prims.bool",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple3"
] | [] | false | true | false | false | false | let sample #s () : NDS bool s =
| NDS?.reflect (fun t n s -> t n, s, n + 1) | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.sha3_state | val sha3_state : a: _ -> Type | let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul } | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 190,
"start_col": 0,
"start_line": 190
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: _ -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Streaming.Keccak.singleton",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Keccak.uint64",
"Prims.eq2",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | true | let sha3_state a =
| singleton a & b: B.buffer uint64 {B.len b == 25ul} | false |
|
OPLSS2021.NDS.fst | OPLSS2021.NDS.lift_pure_nds | val lift_pure_nds (a: _) (wp: pure_wp a) (s: _) (f: (unit -> PURE a wp))
: Pure (nds a s) (requires wp (fun _ -> True)) (ensures fun _ -> True) | val lift_pure_nds (a: _) (wp: pure_wp a) (s: _) (f: (unit -> PURE a wp))
: Pure (nds a s) (requires wp (fun _ -> True)) (ensures fun _ -> True) | let lift_pure_nds a (wp:pure_wp a) s (f : unit -> PURE a wp)
: Pure (nds a s)
(requires wp (fun _ -> True))
(ensures fun _ -> True)
= fun t n s -> f (), s, n | {
"file_name": "examples/oplss2021/OPLSS2021.NDS.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 65,
"start_col": 0,
"start_line": 61
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module OPLSS2021.NDS
(** An effect of nondeterminism and state **)
/// An infinite tape of booleans
let tape = nat -> bool
/// The representation of our effect
/// Takes the tape, a curent position on the tape, and an initial state
/// Returns a result, a new position on the tape, and an new state
let nds (a:Type) (s:Type0) =
tape -> nat -> s -> a & s & nat
let return (a:Type) (x:a) s
: nds a s
= fun t n s -> x, s, n
let bind a b s (f:nds a s) (g:a -> nds b s)
: nds b s
= fun t n s ->
let x, s', n' = f t n s in
g x t n' s'
total
reflectable
effect {
NDS (a:Type) ([@@@ effect_param] st:Type0)
with {repr = nds; return; bind}
}
/// Reading the state
let get #s ()
: NDS s s
= NDS?.reflect (fun t n s -> s, s, n)
/// Writing the state
let put #s (x:s)
: NDS unit s
= NDS?.reflect (fun t n _ -> (), x, n)
/// Sampling a boolean
let sample #s ()
: NDS bool s
= NDS?.reflect (fun t n s -> t n, s, n + 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "OPLSS2021.NDS.fst"
} | [
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "OPLSS2021",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> wp: Prims.pure_wp a -> s: Type0 -> f: (_: Prims.unit -> Prims.PURE a)
-> Prims.Pure (OPLSS2021.NDS.nds a s) | Prims.Pure | [] | [] | [
"Prims.pure_wp",
"Prims.unit",
"OPLSS2021.NDS.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.tuple3",
"OPLSS2021.NDS.nds",
"Prims.l_True"
] | [] | false | false | false | false | false | let lift_pure_nds a (wp: pure_wp a) s (f: (unit -> PURE a wp))
: Pure (nds a s) (requires wp (fun _ -> True)) (ensures fun _ -> True) =
| fun t n s -> f (), s, n | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.hash_buf | val hash_buf : Type0 | let hash_buf = hash_alg & B.buffer uint64 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 84,
"start_col": 0,
"start_line": 84
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Spec.Hash.Definitions.hash_alg",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Keccak.uint64"
] | [] | false | false | false | true | true | let hash_buf =
| hash_alg & B.buffer uint64 | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.hash_buf2 | val hash_buf2 : Type0 | let hash_buf2 = hash_buf & hash_buf | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 85,
"start_col": 0,
"start_line": 85
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Hacl.Streaming.Keccak.hash_buf"
] | [] | false | false | false | true | true | let hash_buf2 =
| hash_buf & hash_buf | false |
|
Lib.Buffer.fsti | Lib.Buffer.gbuffer | val gbuffer : a: Type0 -> Type0 | let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE} | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 46,
"start_col": 7,
"start_line": 46
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.cbuffer",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.IMMUTABLE"
] | [] | false | false | false | true | true | let gbuffer (a: Type0) =
| c: cbuffer a {CB.qual_of c == CB.IMMUTABLE} | false |
|
Lib.Buffer.fsti | Lib.Buffer.buffer | val buffer : a: Type0 -> Type0 | let buffer (a:Type0) = buffer_t MUT a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 37,
"start_col": 7,
"start_line": 37
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT"
] | [] | false | false | false | true | true | let buffer (a: Type0) =
| buffer_t MUT a | false |
|
Lib.Buffer.fsti | Lib.Buffer.ilbuffer | val ilbuffer : a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 73,
"start_col": 7,
"start_line": 73
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.IMMUT"
] | [] | false | false | false | true | true | let ilbuffer (a: Type0) (len: size_t) =
| lbuffer_t IMMUT a len | false |
|
Lib.Buffer.fsti | Lib.Buffer.ibuffer | val ibuffer : a: Type0 -> Type0 | let ibuffer (a:Type0) = buffer_t IMMUT a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 40,
"start_col": 7,
"start_line": 40
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.IMMUT"
] | [] | false | false | false | true | true | let ibuffer (a: Type0) =
| buffer_t IMMUT a | false |
|
Lib.Buffer.fsti | Lib.Buffer.cbuffer | val cbuffer : a: Type0 -> Type0 | let cbuffer (a:Type0) = buffer_t CONST a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 43,
"start_col": 7,
"start_line": 43
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.CONST"
] | [] | false | false | false | true | true | let cbuffer (a: Type0) =
| buffer_t CONST a | false |
|
Lib.Buffer.fsti | Lib.Buffer.clbuffer | val clbuffer : a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 74,
"start_col": 7,
"start_line": 74
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.CONST"
] | [] | false | false | false | true | true | let clbuffer (a: Type0) (len: size_t) =
| lbuffer_t CONST a len | false |
|
Lib.Buffer.fsti | Lib.Buffer.lbuffer | val lbuffer : a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 72,
"start_col": 7,
"start_line": 72
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT"
] | [] | false | false | false | true | true | let lbuffer (a: Type0) (len: size_t) =
| lbuffer_t MUT a len | false |
|
Lib.Buffer.fsti | Lib.Buffer.union | val union (l1 l2: B.loc) : GTot B.loc | val union (l1 l2: B.loc) : GTot B.loc | let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 139,
"start_col": 0,
"start_line": 139
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l1: LowStar.Monotonic.Buffer.loc -> l2: LowStar.Monotonic.Buffer.loc
-> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_union"
] | [] | false | false | false | false | false | let union (l1 l2: B.loc) : GTot B.loc =
| B.loc_union l1 l2 | false |
Lib.Buffer.fsti | Lib.Buffer.modifies | val modifies : s: LowStar.Monotonic.Buffer.loc ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 143,
"start_col": 0,
"start_line": 143
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowStar.Monotonic.Buffer.loc ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.loc",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.modifies"
] | [] | false | false | false | true | true | let modifies (s: B.loc) (h1 h2: HS.mem) =
| B.modifies s h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.disjoint | val disjoint : b1: Lib.Buffer.buffer_t t1 a1 -> b2: Lib.Buffer.buffer_t t2 a2 -> Type0 | let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 152,
"start_col": 0,
"start_line": 151
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b1: Lib.Buffer.buffer_t t1 a1 -> b2: Lib.Buffer.buffer_t t2 a2 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc"
] | [] | false | false | false | false | true | let disjoint (#t1 #t2: buftype) (#a1 #a2: Type0) (b1: buffer_t t1 a1) (b2: buffer_t t2 a2) =
| B.loc_disjoint (loc b1) (loc b2) | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies1 | val modifies1 : b: Lib.Buffer.buffer_t Lib.Buffer.MUT a ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 176,
"start_col": 0,
"start_line": 175
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.buffer_t Lib.Buffer.MUT a ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies1 (#a: Type0) (b: buffer_t MUT a) (h1 h2: HS.mem) =
| modifies (loc b) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies0 | val modifies0 : h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> Type0 | let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 172,
"start_col": 0,
"start_line": 171
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none"
] | [] | false | false | false | true | true | let modifies0 (h1 h2: HS.mem) =
| modifies (B.loc_none) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.lbuffer_t | val lbuffer_t : t: Lib.Buffer.buftype -> a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len} | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 70,
"start_col": 0,
"start_line": 69
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Lib.Buffer.buftype -> a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Lib.Buffer.buffer_t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB"
] | [] | false | false | false | true | true | let lbuffer_t (t: buftype) (a: Type0) (len: size_t) =
| b: buffer_t t a {length #t #a b == v len} | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies2 | val modifies2 : b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 181,
"start_col": 0,
"start_line": 179
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies2 (#a0 #a1: Type0) (b0: buffer_t MUT a0) (b1: buffer_t MUT a1) (h1 h2: HS.mem) =
| modifies (loc b0 |+| loc b1) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies3 | val modifies3 : b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 186,
"start_col": 0,
"start_line": 184
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies3
(#a0 #a1 #a2: Type0)
(b0: buffer_t MUT a0)
(b1: buffer_t MUT a1)
(b2: buffer_t MUT a2)
(h1 h2: HS.mem)
=
| modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.buffer_t | val buffer_t : t: Lib.Buffer.buftype -> a: Type0 -> Type0 | let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 34,
"start_col": 0,
"start_line": 30
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Lib.Buffer.buftype -> a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"LowStar.ImmutableBuffer.ibuffer",
"LowStar.Buffer.buffer",
"LowStar.ConstBuffer.const_buffer"
] | [] | false | false | false | true | true | let buffer_t (t: buftype) (a: Type0) =
| match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies4 | val modifies4 : b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 192,
"start_col": 0,
"start_line": 189
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies4
(#a0 #a1 #a2 #a3: Type0)
(b0: buffer_t MUT a0)
(b1: buffer_t MUT a1)
(b2: buffer_t MUT a2)
(b3: buffer_t MUT a3)
(h1 h2: HS.mem)
=
| modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies5 | val modifies5 : b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
b4: Lib.Buffer.buffer_t Lib.Buffer.MUT a4 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 198,
"start_col": 0,
"start_line": 195
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
b4: Lib.Buffer.buffer_t Lib.Buffer.MUT a4 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies5
(#a0 #a1 #a2 #a3 #a4: Type0)
(b0: buffer_t MUT a0)
(b1: buffer_t MUT a1)
(b2: buffer_t MUT a2)
(b3: buffer_t MUT a3)
(b4: buffer_t MUT a4)
(h1 h2: HS.mem)
=
| modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.modifies6 | val modifies6 : b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
b4: Lib.Buffer.buffer_t Lib.Buffer.MUT a4 ->
b5: Lib.Buffer.buffer_t Lib.Buffer.MUT a5 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 204,
"start_col": 0,
"start_line": 201
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: Lib.Buffer.buffer_t Lib.Buffer.MUT a0 ->
b1: Lib.Buffer.buffer_t Lib.Buffer.MUT a1 ->
b2: Lib.Buffer.buffer_t Lib.Buffer.MUT a2 ->
b3: Lib.Buffer.buffer_t Lib.Buffer.MUT a3 ->
b4: Lib.Buffer.buffer_t Lib.Buffer.MUT a4 ->
b5: Lib.Buffer.buffer_t Lib.Buffer.MUT a5 ->
h1: FStar.Monotonic.HyperStack.mem ->
h2: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc"
] | [] | false | false | false | true | true | let modifies6
(#a0 #a1 #a2 #a3 #a4 #a5: Type0)
(b0: buffer_t MUT a0)
(b1: buffer_t MUT a1)
(b2: buffer_t MUT a2)
(b3: buffer_t MUT a3)
(b4: buffer_t MUT a4)
(b5: buffer_t MUT a5)
(h1 h2: HS.mem)
=
| modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2 | false |
|
Lib.Buffer.fsti | Lib.Buffer.const_to_ilbuffer | val const_to_ilbuffer (#a #len: _) (b: glbuffer a len) : ilbuffer a len | val const_to_ilbuffer (#a #len: _) (b: glbuffer a len) : ilbuffer a len | let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 82,
"start_col": 0,
"start_line": 81
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.glbuffer a len -> Lib.Buffer.ilbuffer a len | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.glbuffer",
"Lib.Buffer.const_to_ibuffer",
"Lib.Buffer.ilbuffer"
] | [] | false | false | false | false | false | let const_to_ilbuffer #a #len (b: glbuffer a len) : ilbuffer a len =
| const_to_ibuffer #a b | false |
Lib.Buffer.fsti | Lib.Buffer.glbuffer | val glbuffer : a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE} | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 75,
"start_col": 7,
"start_line": 75
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.clbuffer",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.IMMUTABLE"
] | [] | false | false | false | true | true | let glbuffer (a: Type0) (len: size_t) =
| c: clbuffer a len {CB.qual_of #a c == CB.IMMUTABLE} | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.get_alg | val get_alg : a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg ->
s:
Hacl.Streaming.Functor.state (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit)
-> FStar.HyperStack.ST.Stack Hacl.Streaming.Keccak.alg | let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 193,
"start_col": 0,
"start_line": 192
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg ->
s:
Hacl.Streaming.Functor.state (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit)
-> FStar.HyperStack.ST.Stack Hacl.Streaming.Keccak.alg | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.index_of_state",
"Hacl.Streaming.Keccak.hacl_keccak",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.state",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Streaming.Functor.invariant",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let get_alg (a: G.erased alg) =
| F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | false |
|
Lib.Buffer.fsti | Lib.Buffer.to_const | val to_const (#a #t: _) (b: buffer_t t a) : r: cbuffer a {length r == length b} | val to_const (#a #t: _) (b: buffer_t t a) : r: cbuffer a {length r == length b} | let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 59,
"start_col": 0,
"start_line": 55
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> r: Lib.Buffer.cbuffer a {Lib.Buffer.length r == Lib.Buffer.length b} | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.ConstBuffer.of_buffer",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.of_ibuffer",
"Lib.Buffer.ibuffer",
"Lib.Buffer.cbuffer",
"Prims.eq2",
"Prims.nat",
"Lib.Buffer.length",
"Lib.Buffer.CONST"
] | [] | false | false | false | false | false | let to_const #a #t (b: buffer_t t a) : r: cbuffer a {length r == length b} =
| match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a | false |
Lib.Buffer.fsti | Lib.Buffer.g_is_null | val g_is_null (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot bool | val g_is_null (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot bool | let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a)) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 94,
"start_col": 0,
"start_line": 90
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cbuffer",
"Prims.bool"
] | [] | false | false | false | false | false | let g_is_null (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot bool =
| match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a)) | false |
Lib.Buffer.fsti | Lib.Buffer.op_Array_Access | val op_Array_Access : b: Lib.Buffer.lbuffer_t t a len ->
i: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v i < Lib.IntTypes.v len}
-> FStar.HyperStack.ST.Stack a | let op_Array_Access #t #a #len = index #t #a #len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 308,
"start_col": 0,
"start_line": 308
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.lbuffer_t t a len ->
i: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v i < Lib.IntTypes.v len}
-> FStar.HyperStack.ST.Stack a | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.index",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Prims.op_LessThan",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.Buffer.as_seq"
] | [] | false | true | false | false | false | let ( .() ) #t #a #len =
| index #t #a #len | false |
|
Lib.Buffer.fsti | Lib.Buffer.alloc_post_mem_common | val alloc_post_mem_common : b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.seq a
-> Prims.logical | let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 348,
"start_col": 0,
"start_line": 341
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.seq a
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.Monotonic.HyperStack.mem",
"Lib.Sequence.seq",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.loc_not_in",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"FStar.Set.equal",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Map.domain",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.HyperStack.get_hmap",
"Prims.eq2",
"FStar.Monotonic.HyperStack.get_tip",
"Lib.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.logical"
] | [] | false | false | false | false | true | let alloc_post_mem_common
(#a: Type0)
(#rrel #rel: LMB.srel a)
(b: LMB.mbuffer a rrel rel)
(h0 h1: HS.mem)
(s: Seq.seq a)
=
| LMB.live h1 b /\ B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
(Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\
(HS.get_tip h1) == (HS.get_tip h0) /\ modifies LMB.loc_none h0 h1 /\ LMB.as_seq h1 b == s | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.coerce | val coerce (#b #a: Type) (x: a{a == b}) : b | val coerce (#b #a: Type) (x: a{a == b}) : b | let coerce (#b #a:Type) (x:a{a == b}) : b = x | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 50,
"start_col": 7,
"start_line": 50
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | x: a{a == b} -> b | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce (#b #a: Type) (x: a{a == b}) : b =
| x | false |
Lib.Buffer.fsti | Lib.Buffer.length | val length : b: Lib.Buffer.buffer_t t a -> Prims.GTot Prims.nat | let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 52,
"start_col": 0,
"start_line": 48
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.ConstBuffer.length",
"Lib.Buffer.cbuffer",
"Prims.nat"
] | [] | false | false | false | false | false | let length (#t: buftype) (#a: Type0) (b: buffer_t t a) =
| match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a) | false |
|
Lib.Buffer.fsti | Lib.Buffer.loc_addr_of_buffer | val loc_addr_of_buffer (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc | val loc_addr_of_buffer (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc | let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a)) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 118,
"start_col": 0,
"start_line": 114
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cbuffer",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc_addr_of_buffer (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc =
| match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a)) | false |
Lib.Buffer.fsti | Lib.Buffer.op_Brack_Lens_Access | val op_Brack_Lens_Access : h: FStar.Monotonic.HyperStack.mem -> b: Lib.Buffer.lbuffer_t t a len
-> Prims.GTot (Lib.Sequence.lseq a (Lib.IntTypes.v len)) | let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 313,
"start_col": 0,
"start_line": 313
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> b: Lib.Buffer.lbuffer_t t a len
-> Prims.GTot (Lib.Sequence.lseq a (Lib.IntTypes.v len)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Lib.Buffer.as_seq",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.lbuffer_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let ( .[||] ) #t #a #len =
| as_seq #t #a #len | false |
|
Lib.Buffer.fsti | Lib.Buffer.const_to_ibuffer | val const_to_ibuffer (#a: _) (b: cbuffer a {CB.qual_of b == CB.IMMUTABLE})
: r: ibuffer a {length r == length b} | val const_to_ibuffer (#a: _) (b: cbuffer a {CB.qual_of b == CB.IMMUTABLE})
: r: ibuffer a {length r == length b} | let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 65,
"start_col": 0,
"start_line": 64
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.cbuffer a {LowStar.ConstBuffer.qual_of b == LowStar.ConstBuffer.IMMUTABLE}
-> r: Lib.Buffer.ibuffer a {Lib.Buffer.length r == Lib.Buffer.length b} | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.cbuffer",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.IMMUTABLE",
"LowStar.ConstBuffer.to_ibuffer",
"Lib.Buffer.ibuffer",
"Prims.nat",
"Lib.Buffer.length",
"Lib.Buffer.IMMUT",
"Lib.Buffer.CONST"
] | [] | false | false | false | false | false | let const_to_ibuffer #a (b: cbuffer a {CB.qual_of b == CB.IMMUTABLE})
: r: ibuffer a {length r == length b} =
| CB.to_ibuffer b | false |
Lib.Buffer.fsti | Lib.Buffer.const_to_buffer | val const_to_buffer (#a: _) (b: cbuffer a {CB.qual_of b == CB.MUTABLE})
: r: buffer a {length r == length b} | val const_to_buffer (#a: _) (b: cbuffer a {CB.qual_of b == CB.MUTABLE})
: r: buffer a {length r == length b} | let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 62,
"start_col": 0,
"start_line": 61
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.cbuffer a {LowStar.ConstBuffer.qual_of b == LowStar.ConstBuffer.MUTABLE}
-> r: Lib.Buffer.buffer a {Lib.Buffer.length r == Lib.Buffer.length b} | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.cbuffer",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.MUTABLE",
"LowStar.ConstBuffer.to_buffer",
"Lib.Buffer.buffer",
"Prims.nat",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST"
] | [] | false | false | false | false | false | let const_to_buffer #a (b: cbuffer a {CB.qual_of b == CB.MUTABLE})
: r: buffer a {length r == length b} =
| CB.to_buffer b | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.free | val free : a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.free_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 199,
"start_col": 0,
"start_line": 198
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.free_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.free",
"Hacl.Streaming.Keccak.hacl_keccak",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.free_st"
] | [] | false | false | false | false | false | let free (a: G.erased alg) =
| F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | false |
|
Lib.Buffer.fsti | Lib.Buffer.op_Array_Assignment | val op_Array_Assignment : b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT a len ->
i: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v i < Lib.IntTypes.v len} ->
x: a
-> FStar.HyperStack.ST.Stack Prims.unit | let op_Array_Assignment #a #len = upd #a #len | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 304,
"start_col": 0,
"start_line": 304
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.lbuffer_t Lib.Buffer.MUT a len ->
i: Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB {Lib.IntTypes.v i < Lib.IntTypes.v len} ->
x: a
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.upd",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Prims.op_LessThan",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Prims.l_and",
"Lib.Buffer.modifies1",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.Buffer.as_seq",
"Lib.Sequence.upd"
] | [] | false | true | false | false | false | let ( .()<- ) #a #len =
| upd #a #len | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.update_multi_s | val update_multi_s : a: Hacl.Streaming.Keccak.alg ->
acc: Spec.Hash.Definitions.words_state a ->
prevlen: Prims.nat ->
input: Spec.Hash.Definitions.bytes_blocks a
-> Spec.Hash.Definitions.words_state a | let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 54,
"start_col": 0,
"start_line": 53
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
a: Hacl.Streaming.Keccak.alg ->
acc: Spec.Hash.Definitions.words_state a ->
prevlen: Prims.nat ->
input: Spec.Hash.Definitions.bytes_blocks a
-> Spec.Hash.Definitions.words_state a | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Keccak.alg",
"Spec.Hash.Definitions.words_state",
"Prims.nat",
"Spec.Hash.Definitions.bytes_blocks",
"Spec.Agile.Hash.update_multi"
] | [] | false | false | false | false | false | let update_multi_s (a: alg) acc (prevlen: nat) input =
| Agile.update_multi a acc () input | false |
|
Lib.Buffer.fsti | Lib.Buffer.null | val null (#t: buftype) (a: Type0) : buffer_t t a | val null (#t: buftype) (a: Type0) : buffer_t t a | let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 88,
"start_col": 7,
"start_line": 84
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Lib.Buffer.buffer_t t a | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"LowStar.ImmutableBuffer.inull",
"LowStar.Buffer.null",
"LowStar.ConstBuffer.null",
"Lib.Buffer.buffer_t"
] | [] | false | false | false | false | false | let null (#t: buftype) (a: Type0) : buffer_t t a =
| match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.malloc | val malloc : a: Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.malloc_st (Hacl.Streaming.Keccak.hacl_keccak (FStar.Ghost.hide a))
a
(Hacl.Streaming.Keccak.sha3_state a)
(FStar.Ghost.erased Prims.unit) | let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 196,
"start_col": 0,
"start_line": 195
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.malloc_st (Hacl.Streaming.Keccak.hacl_keccak (FStar.Ghost.hide a))
a
(Hacl.Streaming.Keccak.sha3_state a)
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.malloc",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.hide",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.erased",
"Prims.unit",
"Hacl.Streaming.Functor.malloc_st"
] | [] | false | false | false | false | false | let malloc (a: alg) =
| F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit) | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.is_shake_ | val is_shake_ : a: Spec.Hash.Definitions.hash_alg -> Prims.bool | let is_shake_ a = a = Shake128 || a = Shake256 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 118,
"start_col": 0,
"start_line": 118
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: Spec.Hash.Definitions.hash_alg -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.op_BarBar",
"Prims.op_Equality",
"Spec.Hash.Definitions.Shake128",
"Spec.Hash.Definitions.Shake256",
"Prims.bool"
] | [] | false | false | false | true | false | let is_shake_ a =
| a = Shake128 || a = Shake256 | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.reset | val reset : a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.reset_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.hide (FStar.Ghost.reveal a))
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 205,
"start_col": 0,
"start_line": 204
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.reset_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.hide (FStar.Ghost.reveal a))
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.reset",
"Hacl.Streaming.Keccak.hacl_keccak",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.reset_st",
"FStar.Ghost.hide"
] | [] | false | false | false | false | false | let reset (a: G.erased alg) =
| F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | false |
|
Lib.Buffer.fsti | Lib.Buffer.loc | val loc (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc | val loc (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc | let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 112,
"start_col": 0,
"start_line": 108
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.ConstBuffer.loc_buffer",
"Lib.Buffer.cbuffer",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot B.loc =
| match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a) | false |
Lib.Buffer.fsti | Lib.Buffer.cpred | val cpred (#a: Type0) (s: Seq.seq a) : B.spred a | val cpred (#a: Type0) (s: Seq.seq a) : B.spred a | let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1 | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 380,
"start_col": 0,
"start_line": 380
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Lib.Sequence.seq a -> LowStar.Monotonic.Buffer.spred a | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.seq",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.spred"
] | [] | false | false | false | true | false | let cpred (#a: Type0) (s: Seq.seq a) : B.spred a =
| fun s1 -> FStar.Seq.equal s s1 | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.update | val update : a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.update_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | let update (a: G.erased alg) =
F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 208,
"start_col": 0,
"start_line": 207
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.update_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.update",
"Hacl.Streaming.Keccak.hacl_keccak",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.update_st"
] | [] | false | false | false | false | false | let update (a: G.erased alg) =
| F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | false |
|
Lib.Buffer.fsti | Lib.Buffer.freeable | val freeable (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot Type0 | val freeable (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot Type0 | let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a)) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 106,
"start_col": 0,
"start_line": 102
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cbuffer"
] | [] | false | false | false | false | true | let freeable (#t: buftype) (#a: Type0) (b: buffer_t t a) : GTot Type0 =
| match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a)) | false |
Lib.Buffer.fsti | Lib.Buffer.const_to_lbuffer | val const_to_lbuffer (#a #len: _) (b: clbuffer a len {CB.qual_of (b <: cbuffer a) == CB.MUTABLE})
: lbuffer a len | val const_to_lbuffer (#a #len: _) (b: clbuffer a len {CB.qual_of (b <: cbuffer a) == CB.MUTABLE})
: lbuffer a len | let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 79,
"start_col": 0,
"start_line": 77
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.clbuffer a len {LowStar.ConstBuffer.qual_of b == LowStar.ConstBuffer.MUTABLE}
-> Lib.Buffer.lbuffer a len | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.clbuffer",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"Lib.Buffer.cbuffer",
"LowStar.ConstBuffer.MUTABLE",
"Lib.Buffer.const_to_buffer",
"Lib.Buffer.lbuffer"
] | [] | false | false | false | false | false | let const_to_lbuffer #a #len (b: clbuffer a len {CB.qual_of (b <: cbuffer a) == CB.MUTABLE})
: lbuffer a len =
| const_to_buffer #a b | false |
Lib.Buffer.fsti | Lib.Buffer.get | val get (#t: buftype) (#a: Type0) (h: mem) (b: buffer_t t a) (i: nat{i < length b}) : GTot a | val get (#t: buftype) (#a: Type0) (h: mem) (b: buffer_t t a) (i: nat{i < length b}) : GTot a | let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 135,
"start_col": 0,
"start_line": 130
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
b: Lib.Buffer.buffer_t t a ->
i: Prims.nat{i < Lib.Buffer.length b}
-> Prims.GTot a | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.buffer_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Buffer.length",
"LowStar.Monotonic.Buffer.get",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cbuffer"
] | [] | false | false | false | false | false | let get (#t: buftype) (#a: Type0) (h: mem) (b: buffer_t t a) (i: nat{i < length b}) : GTot a =
| match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i | false |
Lib.Buffer.fsti | Lib.Buffer.mut_immut_disjoint | val mut_immut_disjoint (#t #t': _) (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)] | val mut_immut_disjoint (#t #t': _) (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)] | let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 160,
"start_col": 0,
"start_line": 154
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.buffer_t Lib.Buffer.MUT t ->
ib: Lib.Buffer.buffer_t Lib.Buffer.IMMUT t' ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires LowStar.Monotonic.Buffer.live h b /\ LowStar.Monotonic.Buffer.live h ib)
(ensures Lib.Buffer.disjoint b ib)
[
SMTPat (LowStar.Monotonic.Buffer.loc_disjoint (Lib.Buffer.loc b) (Lib.Buffer.loc ib));
SMTPat (LowStar.Monotonic.Buffer.live h b);
SMTPat (LowStar.Monotonic.Buffer.live h ib)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.IMMUT",
"FStar.Monotonic.HyperStack.mem",
"LowStar.ImmutableBuffer.buffer_immutable_buffer_disjoint",
"Prims.unit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowStar.ImmutableBuffer.immutable_preorder",
"Prims.squash",
"Lib.Buffer.disjoint",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"Prims.Nil"
] | [] | true | false | true | false | false | let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)] =
| IB.buffer_immutable_buffer_disjoint b ib h | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.copy | val copy : a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.copy_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 202,
"start_col": 0,
"start_line": 201
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.copy_st (Hacl.Streaming.Keccak.hacl_keccak a)
(FStar.Ghost.reveal a)
(Hacl.Streaming.Keccak.sha3_state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.copy",
"Hacl.Streaming.Keccak.hacl_keccak",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.copy_st"
] | [] | false | false | false | false | false | let copy (a: G.erased alg) =
| F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.state_t | val state_t : Type0 | let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 188,
"start_col": 0,
"start_line": 188
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.state_s'",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.hide",
"Spec.Hash.Definitions.SHA3_256"
] | [] | false | false | false | true | true | let state_t =
| F.state_s' (hacl_keccak SHA3_256) SHA3_256 | false |
|
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.digest_ | val digest_ : a: Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Keccak.hacl_keccak (FStar.Ghost.hide a))
a
(Hacl.Streaming.Keccak.sha3_state a)
(FStar.Ghost.erased Prims.unit) | let digest_ (a: alg) =
F.digest #alg (hacl_keccak a) a (sha3_state a) (G.erased unit) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 212,
"start_col": 0,
"start_line": 211
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let update (a: G.erased alg) =
F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: Hacl.Streaming.Keccak.alg
-> Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Keccak.hacl_keccak (FStar.Ghost.hide a))
a
(Hacl.Streaming.Keccak.sha3_state a)
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.digest",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.hide",
"Hacl.Streaming.Keccak.sha3_state",
"FStar.Ghost.erased",
"Prims.unit",
"Hacl.Streaming.Functor.digest_st"
] | [] | false | false | false | false | false | let digest_ (a: alg) =
| F.digest #alg (hacl_keccak a) a (sha3_state a) (G.erased unit) | false |
|
Lib.Buffer.fsti | Lib.Buffer.mut_const_immut_disjoint | val mut_const_immut_disjoint (#t #t': _) (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[
SMTPat (B.loc_disjoint (loc b) (loc ib));
SMTPat (B.live h b);
SMTPat (B.live h (CB.as_mbuf ib))
] | val mut_const_immut_disjoint (#t #t': _) (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[
SMTPat (B.loc_disjoint (loc b) (loc ib));
SMTPat (B.live h b);
SMTPat (B.live h (CB.as_mbuf ib))
] | let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 168,
"start_col": 0,
"start_line": 162
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.buffer_t Lib.Buffer.MUT t ->
ib: Lib.Buffer.buffer_t Lib.Buffer.CONST t' ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.live h b /\
LowStar.Monotonic.Buffer.live h (LowStar.ConstBuffer.as_mbuf ib) /\
LowStar.ConstBuffer.qual_of ib == LowStar.ConstBuffer.IMMUTABLE)
(ensures LowStar.Monotonic.Buffer.loc_disjoint (Lib.Buffer.loc b) (Lib.Buffer.loc ib))
[
SMTPat (LowStar.Monotonic.Buffer.loc_disjoint (Lib.Buffer.loc b) (Lib.Buffer.loc ib));
SMTPat (LowStar.Monotonic.Buffer.live h b);
SMTPat (LowStar.Monotonic.Buffer.live h (LowStar.ConstBuffer.as_mbuf ib))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"FStar.Monotonic.HyperStack.mem",
"LowStar.ImmutableBuffer.buffer_immutable_buffer_disjoint",
"LowStar.ConstBuffer.as_mbuf",
"Prims.unit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.IMMUTABLE",
"Prims.squash",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem)
: Lemma (requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[
SMTPat (B.loc_disjoint (loc b) (loc ib));
SMTPat (B.live h b);
SMTPat (B.live h (CB.as_mbuf ib))
] =
| IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.update_multi_associative | val update_multi_associative (a: alg) (acc: _) (prevlen1 prevlen2: nat) (input1 input2: S.seq uint8)
: Lemma
(requires
(prevlen1 % U32.v (D.block_len a) = 0 /\ S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\ prevlen2 = prevlen1 + S.length input1))
(ensures
(let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\ prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) | val update_multi_associative (a: alg) (acc: _) (prevlen1 prevlen2: nat) (input1 input2: S.seq uint8)
: Lemma
(requires
(prevlen1 % U32.v (D.block_len a) = 0 /\ S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\ prevlen2 = prevlen1 + S.length input1))
(ensures
(let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\ prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) | let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2 | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 77,
"start_col": 0,
"start_line": 63
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1" | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Streaming.Keccak.alg ->
acc: Spec.Hash.Definitions.words_state a ->
prevlen1: Prims.nat ->
prevlen2: Prims.nat ->
input1: FStar.Seq.Base.seq Hacl.Streaming.Interface.uint8 ->
input2: FStar.Seq.Base.seq Hacl.Streaming.Interface.uint8
-> FStar.Pervasives.Lemma
(requires
prevlen1 % FStar.UInt32.v (Hacl.Hash.Definitions.block_len a) = 0 /\
FStar.Seq.Base.length input1 % FStar.UInt32.v (Hacl.Hash.Definitions.block_len a) = 0 /\
FStar.Seq.Base.length input2 % FStar.UInt32.v (Hacl.Hash.Definitions.block_len a) = 0 /\
prevlen2 = prevlen1 + FStar.Seq.Base.length input1)
(ensures
(let input = FStar.Seq.Base.append input1 input2 in
FStar.Seq.Base.length input % FStar.UInt32.v (Hacl.Hash.Definitions.block_len a) = 0 /\
prevlen2 % FStar.UInt32.v (Hacl.Hash.Definitions.block_len a) = 0 /\
Hacl.Streaming.Keccak.update_multi_s a
(Hacl.Streaming.Keccak.update_multi_s a acc prevlen1 input1)
prevlen2
input2 ==
Hacl.Streaming.Keccak.update_multi_s a acc prevlen1 input)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Streaming.Keccak.alg",
"Spec.Hash.Definitions.words_state",
"Prims.nat",
"FStar.Seq.Base.seq",
"Hacl.Streaming.Interface.uint8",
"Spec.Hash.Lemmas.update_multi_associative",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.UInt32.v",
"Hacl.Hash.Definitions.block_len",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Prims.squash",
"Prims.eq2",
"Hacl.Streaming.Keccak.update_multi_s",
"FStar.Seq.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let update_multi_associative
(a: alg)
acc
(prevlen1: nat)
(prevlen2: nat)
(input1: S.seq uint8)
(input2: S.seq uint8)
: Lemma
(requires
(prevlen1 % U32.v (D.block_len a) = 0 /\ S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\ prevlen2 = prevlen1 + S.length input1))
(ensures
(let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\ prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
| Spec.Hash.Lemmas.update_multi_associative a acc input1 input2 | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.update_multi_zero | val update_multi_zero (a: alg) (acc: _) (prevlen: nat)
: Lemma (update_multi_s a acc prevlen S.empty == acc) | val update_multi_zero (a: alg) (acc: _) (prevlen: nat)
: Lemma (update_multi_s a acc prevlen S.empty == acc) | let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: Hacl.Streaming.Keccak.alg -> acc: Spec.Hash.Definitions.words_state a -> prevlen: Prims.nat
-> FStar.Pervasives.Lemma
(ensures Hacl.Streaming.Keccak.update_multi_s a acc prevlen FStar.Seq.Base.empty == acc) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Streaming.Keccak.alg",
"Spec.Hash.Definitions.words_state",
"Prims.nat",
"Spec.Hash.Lemmas.update_multi_zero",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Hacl.Streaming.Keccak.update_multi_s",
"FStar.Seq.Base.empty",
"Lib.IntTypes.uint8",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let update_multi_zero (a: alg) acc (prevlen: nat)
: Lemma (update_multi_s a acc prevlen S.empty == acc) =
| Spec.Hash.Lemmas.update_multi_zero a acc | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.is_shake | val is_shake: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack bool
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
r == is_shake_ a)) | val is_shake: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack bool
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
r == is_shake_ a)) | let is_shake a s =
is_shake_ (get_alg a s) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 360,
"start_col": 0,
"start_line": 359
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let update (a: G.erased alg) =
F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
private
let digest_ (a: alg) =
F.digest #alg (hacl_keccak a) a (sha3_state a) (G.erased unit)
open Hacl.Streaming.Functor
// Unfortunate copy-paste since there are small variations (error code, output length)
val digest:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
Stack error_code
(requires fun h0 ->
(not (is_shake a) ==> B.length dst == Spec.Hash.Definitions.hash_length a) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
match r with
| Success ->
not (is_shake a) /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (Spec.Agile.Hash.hash a (seen c i h0 s)) /\
preserves_freeable c i s h0 h1)
| InvalidAlgorithm ->
is_shake a
| _ ->
False))
let digest a state output =
let a = get_alg a state in
if (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else begin
digest_ a state output (Hacl.Hash.SHA3.hash_len a);
Success
end
// Unfortunate copy-paste since we are returning an error code
val squeeze:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
l:Lib.IntTypes.size_t ->
Stack error_code
(requires fun h0 ->
(is_shake a ==> B.length dst == Lib.IntTypes.v l) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
let _ = allow_inversion error_code in
match r with
| Success ->
is_shake a /\
l <> 0ul /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (c.spec_s i (reveal_key c i h0 s) (seen c i h0 s) l)) /\
preserves_freeable c i s h0 h1
| InvalidAlgorithm ->
not (is_shake a)
| InvalidLength ->
l = 0ul
| _ ->
False))
let squeeze a s dst l =
let a = get_alg a s in
if not (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else if l = 0ul then
InvalidLength
else begin
digest_ a s dst l;
Success
end
val block_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.block_length a /\
Lib.IntTypes.v r == Spec.Hash.Definitions.rate a / 8))
let block_len a s =
let a = get_alg a s in
Hacl.Hash.SHA3.block_len a
val hash_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
not (is_shake_ a) /\
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.hash_length a))
let hash_len a s =
let a = get_alg a s in
Hacl.Hash.SHA3.hash_len a
val is_shake: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack bool
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
r == is_shake_ a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Functor",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> (let c = Hacl.Streaming.Keccak.hacl_keccak a in
let a = FStar.Ghost.reveal a in
let i = a in
let t = Hacl.Streaming.Keccak.sha3_state a in
let t' = FStar.Ghost.erased Prims.unit in
s: Hacl.Streaming.Functor.state c i t t' -> FStar.HyperStack.ST.Stack Prims.bool) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.state",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.reveal",
"Hacl.Streaming.Keccak.sha3_state",
"Prims.unit",
"Hacl.Streaming.Keccak.is_shake_",
"Prims.bool",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Streaming.Keccak.get_alg"
] | [] | false | false | false | false | false | let is_shake a s =
| is_shake_ (get_alg a s) | false |
Lib.Buffer.fsti | Lib.Buffer.is_null | val is_null (#t: buftype) (#a: Type0) (b: buffer_t t a)
: Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) | val is_null (#t: buftype) (#a: Type0) (b: buffer_t t a)
: Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) | let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 128,
"start_col": 0,
"start_line": 121
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.buffer_t t a -> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.buftype",
"Lib.Buffer.buffer_t",
"LowStar.Monotonic.Buffer.is_null",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"Prims.bool",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.is_null",
"Lib.Buffer.cbuffer",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Prims.l_and",
"Prims.eq2",
"Lib.Buffer.g_is_null"
] | [] | false | true | false | false | false | let is_null (#t: buftype) (#a: Type0) (b: buffer_t t a)
: Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
| match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a) | false |
Lib.Buffer.fsti | Lib.Buffer.bget | val bget
(#t: buftype)
(#a: Type0)
(#len: size_t)
(h: mem)
(b: lbuffer_t t a len)
(i: size_nat{i < v len})
: GTot a | val bget
(#t: buftype)
(#a: Type0)
(#len: size_t)
(h: mem)
(b: lbuffer_t t a len)
(i: size_nat{i < v len})
: GTot a | let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 322,
"start_col": 0,
"start_line": 316
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
b: Lib.Buffer.lbuffer_t t a len ->
i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v len}
-> Prims.GTot a | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Monotonic.Buffer.get",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"FStar.Seq.Base.index",
"LowStar.ConstBuffer.as_seq",
"Lib.Buffer.cbuffer"
] | [] | false | false | false | false | false | let bget
(#t: buftype)
(#a: Type0)
(#len: size_t)
(h: mem)
(b: lbuffer_t t a len)
(i: size_nat{i < v len})
: GTot a =
| match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i | false |
Lib.Buffer.fsti | Lib.Buffer.stack_allocated | val stack_allocated : b: Lib.Buffer.lbuffer a len ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.lseq a (Lib.IntTypes.v len)
-> Prims.logical | let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 355,
"start_col": 0,
"start_line": 350
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.lbuffer a len ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.lseq a (Lib.IntTypes.v len)
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"FStar.Monotonic.HyperStack.mem",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.l_and",
"Lib.Buffer.alloc_post_mem_common",
"LowStar.Buffer.trivial_preorder",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"FStar.Monotonic.HyperStack.get_tip",
"Prims.op_disEquality",
"FStar.Monotonic.HyperHeap.root",
"LowStar.Buffer.buffer",
"Prims.logical"
] | [] | false | false | false | false | true | let stack_allocated
(#a: Type0)
(#len: size_t)
(b: lbuffer a len)
(h0 h1: mem)
(s: Seq.lseq a (v len))
=
| let b:B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\ B.frameOf b = HS.get_tip h0 /\ B.frameOf b <> HyperStack.root | false |
|
Lib.Buffer.fsti | Lib.Buffer.recallable | val recallable : b: Lib.Buffer.lbuffer_t t a len -> Type0 | let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a)) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 367,
"start_col": 0,
"start_line": 363
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.lbuffer_t t a len -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"LowStar.Monotonic.Buffer.recallable",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cbuffer"
] | [] | false | false | false | false | true | let recallable (#t: buftype) (#a: Type0) (#len: size_t) (b: lbuffer_t t a len) =
| match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a)) | false |
|
Lib.Buffer.fsti | Lib.Buffer.as_seq | val as_seq (#t: buftype) (#a: Type0) (#len: size_t) (h: HS.mem) (b: lbuffer_t t a len)
: GTot (Seq.lseq a (v len)) | val as_seq (#t: buftype) (#a: Type0) (#len: size_t) (h: HS.mem) (b: lbuffer_t t a len)
: GTot (Seq.lseq a (v len)) | let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 212,
"start_col": 0,
"start_line": 207
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> b: Lib.Buffer.lbuffer_t t a len
-> Prims.GTot (Lib.Sequence.lseq a (Lib.IntTypes.v len)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.lbuffer_t",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Buffer.trivial_preorder",
"Lib.Buffer.buffer",
"LowStar.ImmutableBuffer.immutable_preorder",
"Lib.Buffer.ibuffer",
"LowStar.ConstBuffer.as_seq",
"Lib.Buffer.cbuffer",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let as_seq (#t: buftype) (#a: Type0) (#len: size_t) (h: HS.mem) (b: lbuffer_t t a len)
: GTot (Seq.lseq a (v len)) =
| match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a) | false |
Lib.Buffer.fsti | Lib.Buffer.loop_refl_inv | val loop_refl_inv
(h0: mem)
(n: size_t)
(a_spec: Type)
(refl: (mem -> GTot a_spec))
(footprint: B.loc)
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec -> a_spec)))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | val loop_refl_inv
(h0: mem)
(n: size_t)
(a_spec: Type)
(refl: (mem -> GTot a_spec))
(footprint: B.loc)
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec -> a_spec)))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | let loop_refl_inv
(h0:mem)
(n:size_t)
(a_spec: Type)
(refl:(mem -> GTot a_spec))
(footprint:B.loc)
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec)))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies footprint h0 h /\
refl h == Loop.repeati i (spec h0) (refl h0) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 678,
"start_col": 0,
"start_line": 666
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1
let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s)
(** Allocate a stack fixed-length mutable buffer and initialize it to value [init] *)
inline_for_extraction
val create:
#a:Type0
-> len:size_t
-> init:a ->
StackInline (lbuffer a len)
(requires fun h0 -> v len > 0)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create (v len) init))
#set-options "--max_fuel 1"
(** Allocate a stack fixed-length mutable buffer initialized to a list *)
inline_for_extraction
val createL:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
StackInline (lbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.alloca_of_list_pre #a init)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.of_list init))
(** Allocate a global fixed-length const immutable buffer initialized to value [init] *)
inline_for_extraction
val createL_global:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
ST (glbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.gcmalloc_of_list_pre #a HyperStack.root init)
(ensures fun h0 b h1 -> global_allocated b h0 h1 (Seq.of_list init) /\
recallable b /\
witnessed b (Seq.of_list init))
(** Allocate a global fixed-length mutable buffer initialized to value [init] *)
inline_for_extraction
val createL_mglobal: #a:Type0 -> init:list a ->
ST (buffer a)
(requires fun h0 -> normalize (FStar.List.Tot.length init <= max_size_t))
(ensures fun h0 b h1 ->
B.frameOf b == HyperStack.root /\ B.recallable b /\
alloc_post_mem_common (b <: buffer a) h0 h1 (FStar.Seq.seq_of_list init) /\
length b == normalize_term (FStar.List.Tot.length init))
#set-options "--max_fuel 0"
(** Recall the liveness and contents of a global immutable buffer *)
inline_for_extraction
val recall_contents:
#a:Type0
-> #len:size_t{v len <= max_size_t}
-> b:glbuffer a len
-> s:Seq.lseq a (v len) ->
ST unit
(requires fun h0 -> (live h0 b \/ recallable b) /\ witnessed b s)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ as_seq h0 b == s)
(** Copy a buffer into a mutable buffer *)
inline_for_extraction
val copy:
#t:buftype
-> #a:Type
-> #len:size_t
-> o:lbuffer a len
-> i:lbuffer_t t a len ->
Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint i o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == as_seq h0 i)
(**
* Set all elements of a mutable buffer to a specific value
*
* WARNING: don't rely on the extracted implementation for secure erasure,
* C compilers may remove optimize it away.
*)
inline_for_extraction
val memset:
#a:Type
-> #blen:size_t
-> b:lbuffer a blen
-> w:a
-> len:size_t{v len <= v blen} ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 (gsub b 0ul len) == Seq.create (v len) w /\
as_seq h1 (gsub b len (blen -! len)) ==
as_seq h0 (gsub b len (blen -! len)))
(** Copy a buffer into a sub-buffer of a mutable buffer *)
inline_for_extraction
val update_sub:
#t:buftype
-> #a:Type
-> #len:size_t
-> dst:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> src:lbuffer_t t a n ->
Stack unit
(requires fun h -> live h dst /\ live h src /\ disjoint dst src)
(ensures fun h0 _ h1 ->
modifies1 dst h0 h1 /\
as_seq h1 dst == Seq.update_sub (as_seq h0 dst) (v start) (v n) (as_seq h0 src))
(** Update a mutable buffer in-place by applying a function on a sub-buffer of it *)
inline_for_extraction
val update_sub_f:
#a:Type
-> #len:size_t
-> h0:mem
-> buf:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> spec:(mem -> GTot (Seq.lseq a (v n)))
-> f:(unit -> Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 ->
(let b = gsub buf start n in
modifies (loc b) h0 h1 /\
as_seq h1 b == spec h0))) ->
Stack unit
(requires fun h -> h0 == h /\ live h buf)
(ensures fun h0 _ h1 ->
modifies (loc buf) h0 h1 /\
as_seq h1 buf == Seq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) (spec h0))
(** Copy two buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat2:
#t0:buftype
-> #t1:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> s:lbuffer a (len0 +! len1)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s /\
disjoint s s0 /\ disjoint s s1)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (as_seq h0 s0) (as_seq h0 s1))
(** Copy three buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat3:
#t0:buftype
-> #t1:buftype
-> #t2:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> len2:size_t{v len0 + v len1 + v len2 <= max_size_t}
-> s2:lbuffer_t t2 a len2
-> s:lbuffer a (len0 +! len1 +! len2)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s2 /\ live h s /\
disjoint s s0 /\ disjoint s s1 /\ disjoint s s2)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (Seq.concat (as_seq h0 s0) (as_seq h0 s1)) (as_seq h0 s2))
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> n:size_t
-> buf:lbuffer a len
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec2:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #len1:size_t
-> #len2:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies2 buf1 buf2 h0 h)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec3:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #a3:Type0
-> #len1:size_t
-> #len2:size_t
-> #len3:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> buf3:lbuffer a3 len3
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies3 buf1 buf2 buf3 h0 h)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2 /\ live h0 buf3)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_range_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> start:size_t
-> n:size_t{v start + v n <= max_size_t}
-> buf:lbuffer a len
-> impl: (i:size_t{v start <= v i /\ v i < v start + v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
let loop_inv
(h0:mem)
(n:size_t)
(a_spec:(i:size_nat{i <= v n} -> Type))
(refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i)))
(footprint:(i:size_nat{i <= v n} -> GTot B.loc))
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies (footprint i) h0 h /\
refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0)
(**
* A generalized loop combinator paremetrized by its state (e.g. an accumulator)
*
* Arguments:
* - [h0] the heap when entering the loop
* - [n] the number of iterations
* - [a_spec] the type for the specification state (may depend on the loop index)
* - [refl] a ghost function that reflects the Low* state in an iteration as [a_spec]
* - [footprint] locations modified by the loop (may depend on the loop index)
* - [spec] a specification of how the body of the loop modifies the state
* - [impl] the body of the loop as a Stack function
*)
inline_for_extraction
val loop:
h0:mem
-> n:size_t
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot B.loc)
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_inv h0 n a_spec refl footprint spec (v n) h1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
n: Lib.IntTypes.size_t ->
a_spec: Type ->
refl: (_: FStar.Monotonic.HyperStack.mem -> Prims.GTot a_spec) ->
footprint: LowStar.Monotonic.Buffer.loc ->
spec:
(_: FStar.Monotonic.HyperStack.mem
-> Prims.GTot (i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n} -> _: a_spec -> a_spec)) ->
i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} ->
h: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Lib.IntTypes.size_t",
"LowStar.Monotonic.Buffer.loc",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Prims.l_and",
"Lib.Buffer.modifies",
"Prims.eq2",
"Lib.LoopCombinators.repeati"
] | [] | false | false | false | false | true | let loop_refl_inv
(h0: mem)
(n: size_t)
(a_spec: Type)
(refl: (mem -> GTot a_spec))
(footprint: B.loc)
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec -> a_spec)))
(i: size_nat{i <= v n})
(h: mem)
: Type0 =
| modifies footprint h0 h /\ refl h == Loop.repeati i (spec h0) (refl h0) | false |
LowParse.Slice.fst | LowParse.Slice.srel_of_buffer_srel | val srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) | val srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) | let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
s | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 20,
"start_col": 0,
"start_line": 19
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction
noextract
let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowStar.Monotonic.Buffer.srel a -> LowParse.Slice.srel a | Prims.Tot | [
"total"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowParse.Slice.srel"
] | [] | false | false | false | true | false | let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
| s | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.stateful_keccak | val stateful_keccak:stateful alg | val stateful_keccak:stateful alg | let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul) | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 115,
"start_col": 0,
"start_line": 88
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Hacl.Streaming.Interface.stateful Hacl.Streaming.Keccak.alg | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Interface.Stateful",
"Hacl.Streaming.Keccak.alg",
"FStar.Pervasives.Native.tuple2",
"Hacl.Streaming.Keccak.singleton",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Keccak.uint64",
"Prims.eq2",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Monotonic.Buffer.live",
"FStar.Seq.Base.seq",
"Prims.int",
"FStar.Seq.Base.length",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.unit",
"FStar.Pervasives.Native.Mktuple2",
"FStar.UInt32.uint_to_t",
"LowStar.Buffer.alloca",
"Lib.IntTypes.u64",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Buffer.malloc",
"LowStar.Monotonic.Buffer.frameOf",
"FStar.Ghost.erased",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.free",
"LowStar.Monotonic.Buffer.blit"
] | [] | false | false | false | true | false | let stateful_keccak:stateful alg =
| Stateful (fun (a: alg) -> singleton a & b: B.buffer uint64 {B.len b == 25ul})
(fun #_ h (_, s) -> B.loc_addr_of_buffer s)
(fun #_ h (_, s) -> B.freeable s)
(fun #_ h (_, s) -> B.live h s)
(fun _ -> s: S.seq uint64 {S.length s == 25})
(fun _ h (a, s) -> B.as_seq h s)
(fun #_ h (_, s) -> ())
(fun #_ l (_, s) h0 h1 -> ())
(fun #_ l (_, s) h0 h1 -> ())
(fun (a: alg) -> a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(fun a r -> a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(fun _ (_, s) -> B.free s)
(fun _ (a, s_src) (a', s_dst) -> B.blit s_src 0ul s_dst 0ul 25ul) | false |
LowParse.Slice.fst | LowParse.Slice.buffer_srel_of_srel | val buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) | val buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) | let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 15,
"start_col": 0,
"start_line": 14
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Slice.srel a -> LowStar.Monotonic.Buffer.srel a | Prims.Tot | [
"total"
] | [] | [
"LowParse.Slice.srel",
"LowStar.Monotonic.Buffer.srel"
] | [] | false | false | false | true | false | let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
| s | false |
Lib.Buffer.fsti | Lib.Buffer.global_allocated | val global_allocated : b: Lib.Buffer.glbuffer a len ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.lseq a (Lib.IntTypes.v len)
-> Prims.GTot Prims.logical | let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 361,
"start_col": 0,
"start_line": 357
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.glbuffer a len ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem ->
s: Lib.Sequence.lseq a (Lib.IntTypes.v len)
-> Prims.GTot Prims.logical | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.glbuffer",
"FStar.Monotonic.HyperStack.mem",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.l_and",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.ImmutableBuffer.immutable_preorder",
"FStar.Monotonic.HyperHeap.root",
"Lib.Buffer.alloc_post_mem_common",
"Lib.Buffer.buffer_t",
"Lib.Buffer.IMMUT",
"LowStar.ConstBuffer.as_mbuf",
"Prims.logical"
] | [] | false | false | false | false | true | let global_allocated
(#a: Type0)
(#len: size_t)
(b: glbuffer a len)
(h0 h1: mem)
(s: Seq.lseq a (v len))
=
| let b:ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\ alloc_post_mem_common b h0 h1 s | false |
|
LowParse.Slice.fst | LowParse.Slice.loc_slice_from_to | val loc_slice_from_to (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : GTot B.loc | val loc_slice_from_to (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : GTot B.loc | let loc_slice_from_to (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : GTot B.loc =
B.loc_buffer_from_to s.base pos pos' | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 55,
"start_col": 0,
"start_line": 54
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction
noextract
let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s
inline_for_extraction
noextract
let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
s
let buffer_srel_of_srel_of_buffer_srel (#a: Type) (s: B.srel a) : Lemma
(buffer_srel_of_srel (srel_of_buffer_srel s) == s)
[SMTPat (buffer_srel_of_srel (srel_of_buffer_srel s))]
= ()
noeq
inline_for_extraction
type slice (rrel rel: srel byte) = {
base: B.mbuffer byte (buffer_srel_of_srel rrel) (buffer_srel_of_srel rel);
len: (len: U32.t { U32.v len <= B.length base } );
}
inline_for_extraction
noextract
let make_slice
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t { U32.v len <= B.length b } )
: Tot (slice (srel_of_buffer_srel rrel) (srel_of_buffer_srel rel))
= {
base = b;
len = len;
}
let live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 = B.live h s.base
let bytes_of_slice_from (#rrel #rel: _)
(h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes =
if (U32.v pos <= U32.v s.len)
then Seq.slice (B.as_seq h s.base) (U32.v pos) (U32.v s.len)
else Seq.empty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t
-> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc_slice_from_to (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : GTot B.loc =
| B.loc_buffer_from_to s.base pos pos' | false |
LowParse.Slice.fst | LowParse.Slice.live_slice | val live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 | val live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 | let live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 = B.live h s.base | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 94,
"end_line": 46,
"start_col": 0,
"start_line": 46
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction
noextract
let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s
inline_for_extraction
noextract
let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
s
let buffer_srel_of_srel_of_buffer_srel (#a: Type) (s: B.srel a) : Lemma
(buffer_srel_of_srel (srel_of_buffer_srel s) == s)
[SMTPat (buffer_srel_of_srel (srel_of_buffer_srel s))]
= ()
noeq
inline_for_extraction
type slice (rrel rel: srel byte) = {
base: B.mbuffer byte (buffer_srel_of_srel rrel) (buffer_srel_of_srel rel);
len: (len: U32.t { U32.v len <= B.length base } );
}
inline_for_extraction
noextract
let make_slice
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t { U32.v len <= B.length b } )
: Tot (slice (srel_of_buffer_srel rrel) (srel_of_buffer_srel rel))
= {
base = b;
len = len;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 -> s: LowParse.Slice.slice rrel rel -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"LowStar.Monotonic.Buffer.live",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base"
] | [] | false | false | false | false | true | let live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 =
| B.live h s.base | false |
LowParse.Slice.fst | LowParse.Slice.loc_slice_from | val loc_slice_from (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : GTot B.loc | val loc_slice_from (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : GTot B.loc | let loc_slice_from (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : GTot B.loc =
loc_slice_from_to s pos s.len | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction
noextract
let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s
inline_for_extraction
noextract
let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
s
let buffer_srel_of_srel_of_buffer_srel (#a: Type) (s: B.srel a) : Lemma
(buffer_srel_of_srel (srel_of_buffer_srel s) == s)
[SMTPat (buffer_srel_of_srel (srel_of_buffer_srel s))]
= ()
noeq
inline_for_extraction
type slice (rrel rel: srel byte) = {
base: B.mbuffer byte (buffer_srel_of_srel rrel) (buffer_srel_of_srel rel);
len: (len: U32.t { U32.v len <= B.length base } );
}
inline_for_extraction
noextract
let make_slice
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t { U32.v len <= B.length b } )
: Tot (slice (srel_of_buffer_srel rrel) (srel_of_buffer_srel rel))
= {
base = b;
len = len;
}
let live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 = B.live h s.base
let bytes_of_slice_from (#rrel #rel: _)
(h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes =
if (U32.v pos <= U32.v s.len)
then Seq.slice (B.as_seq h s.base) (U32.v pos) (U32.v s.len)
else Seq.empty
let loc_slice_from_to (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : GTot B.loc =
B.loc_buffer_from_to s.base pos pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc_slice_from (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : GTot B.loc =
| loc_slice_from_to s pos s.len | false |
Lib.Buffer.fsti | Lib.Buffer.gsub | val gsub
(#t: buftype)
(#a: Type0)
(#len: size_t)
(b: lbuffer_t t a len)
(start: size_t)
(n: size_t{v start + v n <= v len})
: GTot (lbuffer_t t a n) | val gsub
(#t: buftype)
(#a: Type0)
(#len: size_t)
(b: lbuffer_t t a len)
(start: size_t)
(n: size_t{v start + v n <= v len})
: GTot (lbuffer_t t a n) | let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 230,
"start_col": 0,
"start_line": 215
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Buffer.lbuffer_t t a len ->
start: Lib.IntTypes.size_t ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v start + Lib.IntTypes.v n <= Lib.IntTypes.v len}
-> Prims.GTot (Lib.Buffer.lbuffer_t t a n) | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.ilbuffer",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"LowStar.Monotonic.Buffer.length",
"LowStar.ImmutableBuffer.immutable_preorder",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.ImmutableBuffer.igsub",
"Lib.Buffer.ibuffer",
"Lib.Buffer.lbuffer",
"LowStar.Buffer.trivial_preorder",
"LowStar.Buffer.gsub",
"Lib.Buffer.buffer",
"Lib.Buffer.clbuffer",
"LowStar.ConstBuffer.length",
"LowStar.ConstBuffer.const_buffer",
"LowStar.ConstBuffer.gsub",
"Lib.Buffer.cbuffer"
] | [] | false | false | false | false | false | let gsub
(#t: buftype)
(#a: Type0)
(#len: size_t)
(b: lbuffer_t t a len)
(start: size_t)
(n: size_t{v start + v n <= v len})
: GTot (lbuffer_t t a n) =
| match t with
| IMMUT ->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n) | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.block_len | val block_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.block_length a /\
Lib.IntTypes.v r == Spec.Hash.Definitions.rate a / 8)) | val block_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.block_length a /\
Lib.IntTypes.v r == Spec.Hash.Definitions.rate a / 8)) | let block_len a s =
let a = get_alg a s in
Hacl.Hash.SHA3.block_len a | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 324,
"start_col": 0,
"start_line": 322
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let update (a: G.erased alg) =
F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
private
let digest_ (a: alg) =
F.digest #alg (hacl_keccak a) a (sha3_state a) (G.erased unit)
open Hacl.Streaming.Functor
// Unfortunate copy-paste since there are small variations (error code, output length)
val digest:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
Stack error_code
(requires fun h0 ->
(not (is_shake a) ==> B.length dst == Spec.Hash.Definitions.hash_length a) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
match r with
| Success ->
not (is_shake a) /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (Spec.Agile.Hash.hash a (seen c i h0 s)) /\
preserves_freeable c i s h0 h1)
| InvalidAlgorithm ->
is_shake a
| _ ->
False))
let digest a state output =
let a = get_alg a state in
if (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else begin
digest_ a state output (Hacl.Hash.SHA3.hash_len a);
Success
end
// Unfortunate copy-paste since we are returning an error code
val squeeze:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
l:Lib.IntTypes.size_t ->
Stack error_code
(requires fun h0 ->
(is_shake a ==> B.length dst == Lib.IntTypes.v l) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
let _ = allow_inversion error_code in
match r with
| Success ->
is_shake a /\
l <> 0ul /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (c.spec_s i (reveal_key c i h0 s) (seen c i h0 s) l)) /\
preserves_freeable c i s h0 h1
| InvalidAlgorithm ->
not (is_shake a)
| InvalidLength ->
l = 0ul
| _ ->
False))
let squeeze a s dst l =
let a = get_alg a s in
if not (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else if l = 0ul then
InvalidLength
else begin
digest_ a s dst l;
Success
end
val block_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.block_length a /\
Lib.IntTypes.v r == Spec.Hash.Definitions.rate a / 8)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Functor",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> (let c = Hacl.Streaming.Keccak.hacl_keccak a in
let a = FStar.Ghost.reveal a in
let i = a in
let t = Hacl.Streaming.Keccak.sha3_state a in
let t' = FStar.Ghost.erased Prims.unit in
s: Hacl.Streaming.Functor.state c i t t' -> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.state",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.reveal",
"Hacl.Streaming.Keccak.sha3_state",
"Prims.unit",
"Hacl.Hash.SHA3.block_len",
"Lib.IntTypes.size_t",
"Hacl.Streaming.Keccak.get_alg"
] | [] | false | false | false | false | false | let block_len a s =
| let a = get_alg a s in
Hacl.Hash.SHA3.block_len a | false |
Lib.Buffer.fsti | Lib.Buffer.eq_or_disjoint | val eq_or_disjoint : b1: Lib.Buffer.lbuffer_t t1 a1 clen1 -> b2: Lib.Buffer.lbuffer_t t2 a2 clen2 -> Prims.logical | let eq_or_disjoint
(#t1:buftype)
(#t2:buftype)
(#a1:Type)
(#a2:Type)
(#clen1:size_t)
(#clen2:size_t)
(b1:lbuffer_t t1 a1 clen1)
(b2:lbuffer_t t2 a2 clen2) =
disjoint b1 b2 \/
(t1 == t2 /\ a1 == a2 /\ clen1 == clen2 /\ b1 == b2) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 1129,
"start_col": 0,
"start_line": 1119
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1
let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s)
(** Allocate a stack fixed-length mutable buffer and initialize it to value [init] *)
inline_for_extraction
val create:
#a:Type0
-> len:size_t
-> init:a ->
StackInline (lbuffer a len)
(requires fun h0 -> v len > 0)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create (v len) init))
#set-options "--max_fuel 1"
(** Allocate a stack fixed-length mutable buffer initialized to a list *)
inline_for_extraction
val createL:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
StackInline (lbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.alloca_of_list_pre #a init)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.of_list init))
(** Allocate a global fixed-length const immutable buffer initialized to value [init] *)
inline_for_extraction
val createL_global:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
ST (glbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.gcmalloc_of_list_pre #a HyperStack.root init)
(ensures fun h0 b h1 -> global_allocated b h0 h1 (Seq.of_list init) /\
recallable b /\
witnessed b (Seq.of_list init))
(** Allocate a global fixed-length mutable buffer initialized to value [init] *)
inline_for_extraction
val createL_mglobal: #a:Type0 -> init:list a ->
ST (buffer a)
(requires fun h0 -> normalize (FStar.List.Tot.length init <= max_size_t))
(ensures fun h0 b h1 ->
B.frameOf b == HyperStack.root /\ B.recallable b /\
alloc_post_mem_common (b <: buffer a) h0 h1 (FStar.Seq.seq_of_list init) /\
length b == normalize_term (FStar.List.Tot.length init))
#set-options "--max_fuel 0"
(** Recall the liveness and contents of a global immutable buffer *)
inline_for_extraction
val recall_contents:
#a:Type0
-> #len:size_t{v len <= max_size_t}
-> b:glbuffer a len
-> s:Seq.lseq a (v len) ->
ST unit
(requires fun h0 -> (live h0 b \/ recallable b) /\ witnessed b s)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ as_seq h0 b == s)
(** Copy a buffer into a mutable buffer *)
inline_for_extraction
val copy:
#t:buftype
-> #a:Type
-> #len:size_t
-> o:lbuffer a len
-> i:lbuffer_t t a len ->
Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint i o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == as_seq h0 i)
(**
* Set all elements of a mutable buffer to a specific value
*
* WARNING: don't rely on the extracted implementation for secure erasure,
* C compilers may remove optimize it away.
*)
inline_for_extraction
val memset:
#a:Type
-> #blen:size_t
-> b:lbuffer a blen
-> w:a
-> len:size_t{v len <= v blen} ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 (gsub b 0ul len) == Seq.create (v len) w /\
as_seq h1 (gsub b len (blen -! len)) ==
as_seq h0 (gsub b len (blen -! len)))
(** Copy a buffer into a sub-buffer of a mutable buffer *)
inline_for_extraction
val update_sub:
#t:buftype
-> #a:Type
-> #len:size_t
-> dst:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> src:lbuffer_t t a n ->
Stack unit
(requires fun h -> live h dst /\ live h src /\ disjoint dst src)
(ensures fun h0 _ h1 ->
modifies1 dst h0 h1 /\
as_seq h1 dst == Seq.update_sub (as_seq h0 dst) (v start) (v n) (as_seq h0 src))
(** Update a mutable buffer in-place by applying a function on a sub-buffer of it *)
inline_for_extraction
val update_sub_f:
#a:Type
-> #len:size_t
-> h0:mem
-> buf:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> spec:(mem -> GTot (Seq.lseq a (v n)))
-> f:(unit -> Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 ->
(let b = gsub buf start n in
modifies (loc b) h0 h1 /\
as_seq h1 b == spec h0))) ->
Stack unit
(requires fun h -> h0 == h /\ live h buf)
(ensures fun h0 _ h1 ->
modifies (loc buf) h0 h1 /\
as_seq h1 buf == Seq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) (spec h0))
(** Copy two buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat2:
#t0:buftype
-> #t1:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> s:lbuffer a (len0 +! len1)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s /\
disjoint s s0 /\ disjoint s s1)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (as_seq h0 s0) (as_seq h0 s1))
(** Copy three buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat3:
#t0:buftype
-> #t1:buftype
-> #t2:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> len2:size_t{v len0 + v len1 + v len2 <= max_size_t}
-> s2:lbuffer_t t2 a len2
-> s:lbuffer a (len0 +! len1 +! len2)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s2 /\ live h s /\
disjoint s s0 /\ disjoint s s1 /\ disjoint s s2)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (Seq.concat (as_seq h0 s0) (as_seq h0 s1)) (as_seq h0 s2))
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> n:size_t
-> buf:lbuffer a len
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec2:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #len1:size_t
-> #len2:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies2 buf1 buf2 h0 h)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec3:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #a3:Type0
-> #len1:size_t
-> #len2:size_t
-> #len3:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> buf3:lbuffer a3 len3
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies3 buf1 buf2 buf3 h0 h)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2 /\ live h0 buf3)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_range_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> start:size_t
-> n:size_t{v start + v n <= max_size_t}
-> buf:lbuffer a len
-> impl: (i:size_t{v start <= v i /\ v i < v start + v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
let loop_inv
(h0:mem)
(n:size_t)
(a_spec:(i:size_nat{i <= v n} -> Type))
(refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i)))
(footprint:(i:size_nat{i <= v n} -> GTot B.loc))
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies (footprint i) h0 h /\
refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0)
(**
* A generalized loop combinator paremetrized by its state (e.g. an accumulator)
*
* Arguments:
* - [h0] the heap when entering the loop
* - [n] the number of iterations
* - [a_spec] the type for the specification state (may depend on the loop index)
* - [refl] a ghost function that reflects the Low* state in an iteration as [a_spec]
* - [footprint] locations modified by the loop (may depend on the loop index)
* - [spec] a specification of how the body of the loop modifies the state
* - [impl] the body of the loop as a Stack function
*)
inline_for_extraction
val loop:
h0:mem
-> n:size_t
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot B.loc)
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_inv h0 n a_spec refl footprint spec (v n) h1)
let loop_refl_inv
(h0:mem)
(n:size_t)
(a_spec: Type)
(refl:(mem -> GTot a_spec))
(footprint:B.loc)
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec)))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies footprint h0 h /\
refl h == Loop.repeati i (spec h0) (refl h0)
inline_for_extraction
val loop_refl:
h0:mem
-> n:size_t
-> a_spec:Type
-> refl:(mem -> GTot a_spec)
-> footprint:Ghost.erased B.loc
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_refl_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_refl_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_refl_inv h0 n a_spec refl footprint spec (v n) h1)
let loop1_inv
(h0:mem)
(n:size_t)
(b: Type)
(blen: size_t)
(write:lbuffer b blen)
(spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies1 write h0 h /\
as_seq h write == Loop.repeati i (spec h0) (as_seq h0 write)
(** Loop combinator specialized to modifying a single buffer [write] *)
inline_for_extraction
val loop1:
#b:Type
-> #blen:size_t
-> h0:mem
-> n:size_t
-> write:lbuffer b blen
-> spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop1_inv h0 n b blen write spec (v i))
(ensures fun _ _ -> loop1_inv h0 n b blen write spec (v i + 1))) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun _ _ -> loop1_inv h0 n b blen write spec (v n))
let loop2_inv
(#b0:Type)
(#blen0:size_t)
(#b1:Type)
(#blen1:size_t)
(h0:mem)
(n:size_t)
(write0:lbuffer b0 blen0)
(write1:lbuffer b1 blen1)
(spec:(mem -> GTot (i:size_nat{i < v n}
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1))
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies2 write0 write1 h0 h /\
(let s0, s1 = Loop.repeati i (spec h0) (as_seq h0 write0, as_seq h0 write1) in
as_seq h write0 == s0 /\ as_seq h write1 == s1)
(** Loop combinator specialized to modifying two buffers [write0] and [write1] *)
inline_for_extraction
val loop2:
#b0:Type
-> #blen0:size_t
-> #b1:Type
-> #blen1:size_t
-> h0:mem
-> n:size_t
-> write0:lbuffer b0 blen0
-> write1:lbuffer b1 blen1
-> spec:(mem -> GTot (i:size_nat{i < v n}
-> (Seq.lseq b0 (v blen0) & Seq.lseq b1 (v blen1))
-> (Seq.lseq b0 (v blen0) & Seq.lseq b1 (v blen1))))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop2_inv #b0 #blen0 #b1 #blen1 h0 n write0 write1 spec (v i))
(ensures fun _ _ -> loop2_inv #b0 #blen0 #b1 #blen1 h0 n write0 write1 spec (v i + 1))) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun _ _ -> loop2_inv #b0 #blen0 #b1 #blen1 h0 n write0 write1 spec (v n))
(**
* Allocates a mutable buffer [b] in the stack, calls [impl b] and ovewrites the contents
* of [b] before returning.
*
* [spec] is the functional post-condition of [impl], it only takes the final memory
* because the initial memory is determined by [h]
* [spec_inv] is used to propagate the post-condition of [impl] to the final memory
* after popping the stack frame
*)
inline_for_extraction
val salloc1_with_inv:
#a:Type
-> #res:Type
-> h:mem
-> len:size_t{0 < v len}
-> x:a
-> footprint:Ghost.erased B.loc
-> spec: (res -> mem -> GTot Type0)
-> spec_inv:(h1:mem -> h2:mem -> h3:mem -> r:res -> Lemma
(requires
B.modifies (B.loc_none) h h1 /\
B.modifies (B.loc_union (B.loc_all_regions_from false (get_tip h1))
(Ghost.reveal footprint)) h1 h2 /\
B.modifies (B.loc_region_only false (get_tip h1)) h2 h3 /\
~(live_region h (get_tip h1)) /\
spec r h2)
(ensures spec r h3))
-> impl:(b:lbuffer a len -> Stack res
(requires fun h0 ->
let b:buffer a = b in
B.modifies (B.loc_none) h h0 /\ ~(live_region h (get_tip h0)) /\
B.frameOf b == get_tip h0 /\ B.live h0 b /\ B.as_seq h0 b == Seq.create (v len) x)
(ensures fun h0 r h1 ->
B.modifies (B.loc_union (B.loc_all_regions_from false (get_tip h0))
(Ghost.reveal footprint)) h0 h1 /\
spec r h1)) ->
Stack res
(requires fun h0 -> h0 == h)
(ensures fun h0 r h1 -> modifies (Ghost.reveal footprint) h0 h1 /\ spec r h1)
inline_for_extraction
val salloc1:
#a:Type
-> #res:Type
-> h:mem
-> len:size_t{0 < v len}
-> x:a
-> footprint:Ghost.erased B.loc
-> spec: (res -> mem -> GTot Type0)
-> impl:(b:lbuffer a len -> Stack res
(requires fun h0 ->
let b : buffer a = b in
B.modifies (B.loc_none) h h0 /\ ~(live_region h (get_tip h0)) /\
B.frameOf b == get_tip h0 /\ B.live h0 b /\ B.as_seq h0 b == Seq.create (v len) x)
(ensures fun h0 r h1 ->
B.modifies (B.loc_union (B.loc_all_regions_from false (get_tip h0))
(Ghost.reveal footprint)) h0 h1 /\
spec r h1)) ->
Stack res
(requires fun h0 -> h0 == h /\
(forall (h1 h2 h3:mem) (r:res).
(B.modifies (B.loc_none) h h1 /\
B.modifies (B.loc_union (B.loc_all_regions_from false (get_tip h1))
(Ghost.reveal footprint)) h1 h2 /\
B.modifies (B.loc_region_only false (get_tip h1)) h2 h3 /\
~(live_region h (get_tip h1)) /\
spec r h2) ==> spec r h3))
(ensures fun h0 r h1 -> modifies (Ghost.reveal footprint) h0 h1 /\ spec r h1)
inline_for_extraction
val salloc_nospec:
#a:Type
-> #res:Type
-> h:mem
-> len:size_t{0 < v len}
-> x:a
-> footprint:Ghost.erased B.loc
-> impl:(b:lbuffer a len -> Stack res
(requires fun h0 ->
let b:buffer a = b in
B.modifies (B.loc_none) h h0 /\ ~(live_region h (get_tip h0)) /\
B.frameOf b == get_tip h0 /\ B.live h0 b /\ B.as_seq h0 b == Seq.create (v len) x)
(ensures fun h0 r h1 ->
B.modifies (B.loc_union (B.loc_all_regions_from false (get_tip h0))
(Ghost.reveal footprint)) h0 h1)) ->
Stack res
(requires fun h0 -> h0 == h)
(ensures fun h0 r h1 -> modifies (Ghost.reveal footprint) h0 h1)
inline_for_extraction
val loopi_blocks:
#a:Type0
-> #b:Type0
-> #blen:size_t
-> blocksize:size_t{v blocksize > 0}
-> inpLen:size_t
-> inp:lbuffer a inpLen
-> spec_f:(i:nat{i < v inpLen / v blocksize}
-> Seq.lseq a (v blocksize)
-> Seq.lseq b (v blen)
-> Seq.lseq b (v blen))
-> spec_l:(i:nat{i == v inpLen / v blocksize}
-> len:size_nat{len == v inpLen % v blocksize}
-> s:Seq.lseq a len
-> Seq.lseq b (v blen)
-> Seq.lseq b (v blen))
-> f:(i:size_t{v i < v inpLen / v blocksize}
-> inp:lbuffer a blocksize
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ disjoint inp w)
(ensures fun h0 _ h1 ->
modifies1 w h0 h1 /\
as_seq h1 w == spec_f (v i) (as_seq h0 inp) (as_seq h0 w)))
-> l:(i:size_t{v i == v inpLen / v blocksize}
-> len:size_t{v len == v inpLen % v blocksize}
-> inp:lbuffer a len
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ disjoint inp w)
(ensures fun h0 _ h1 ->
modifies1 w h0 h1 /\
as_seq h1 w == spec_l (v i) (v len) (as_seq h0 inp) (as_seq h0 w)))
-> write:lbuffer b blen ->
Stack unit
(requires fun h -> live h inp /\ live h write /\ disjoint inp write)
(ensures fun h0 _ h1 ->
modifies1 write h0 h1 /\
as_seq h1 write ==
Seq.repeati_blocks #a #(Seq.lseq b (v blen)) (v blocksize) (as_seq h0 inp) spec_f spec_l (as_seq h0 write))
inline_for_extraction
val loopi_blocks_nospec:
#a:Type0
-> #b:Type0
-> #blen:size_t
-> blocksize:size_t{v blocksize > 0}
-> inpLen:size_t
-> inp:lbuffer a inpLen
-> f:(i:size_t{v i < v inpLen / v blocksize}
-> inp:lbuffer a blocksize
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ B.loc_disjoint (loc inp) (loc w))
(ensures fun h0 _ h1 ->
modifies1 w h0 h1))
-> l:(i:size_t{v i == v inpLen / v blocksize}
-> len:size_t{v len == v inpLen % v blocksize}
-> inp:lbuffer a len
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ B.loc_disjoint (loc inp) (loc w))
(ensures fun h0 _ h1 ->
modifies1 w h0 h1))
-> write:lbuffer b blen ->
Stack unit
(requires fun h -> live h inp /\ live h write /\ disjoint inp write)
(ensures fun h0 _ h1 -> modifies1 write h0 h1)
open FStar.Mul
inline_for_extraction
val loop_blocks_multi:
#a:Type0
-> #b:Type0
-> #blen:size_t
-> blocksize:size_t{v blocksize > 0}
-> n_blocks:size_t { v n_blocks * v blocksize < pow2 32 }
-> inp:lbuffer a (blocksize *! n_blocks) {v n_blocks == length inp / v blocksize }
-> spec_f:(Seq.lseq a (v blocksize)
-> Seq.lseq b (v blen)
-> Seq.lseq b (v blen))
-> f:(inp:lbuffer a blocksize
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ disjoint inp w)
(ensures fun h0 _ h1 ->
modifies1 w h0 h1 /\
as_seq h1 w == spec_f (as_seq h0 inp) (as_seq h0 w)))
-> write:lbuffer b blen ->
Stack unit
(requires fun h -> live h inp /\ live h write /\ disjoint inp write)
(ensures fun h0 _ h1 ->
modifies1 write h0 h1 /\
as_seq h1 write ==
Seq.repeat_blocks_multi #a #(Seq.lseq b (v blen)) (v blocksize) (as_seq h0 inp) spec_f (as_seq h0 write))
inline_for_extraction
val loop_blocks:
#a:Type0
-> #b:Type0
-> #blen:size_t
-> blocksize:size_t{v blocksize > 0}
-> n_blocks:size_t
-> rem:size_t { v n_blocks * v blocksize + v rem < pow2 32 }
-> inp:lbuffer a (blocksize *! n_blocks +! rem) { v n_blocks == length inp / v blocksize }
-> spec_f:(Seq.lseq a (v blocksize)
-> Seq.lseq b (v blen)
-> Seq.lseq b (v blen))
-> spec_l:(len:size_nat{len < v blocksize}
-> s:Seq.lseq a len
-> Seq.lseq b (v blen)
-> Seq.lseq b (v blen))
-> f:(inp:lbuffer a blocksize
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ disjoint inp w)
(ensures fun h0 _ h1 ->
modifies1 w h0 h1 /\
as_seq h1 w == spec_f (as_seq h0 inp) (as_seq h0 w)))
-> l:(len:size_t{v len < v blocksize}
-> inp:lbuffer a len
-> w:lbuffer b blen -> Stack unit
(requires fun h ->
live h inp /\ live h w /\ disjoint inp w)
(ensures fun h0 _ h1 ->
modifies1 w h0 h1 /\
as_seq h1 w == spec_l (v len) (as_seq h0 inp) (as_seq h0 w)))
-> write:lbuffer b blen ->
Stack unit
(requires fun h -> live h inp /\ live h write /\ disjoint inp write)
(ensures fun h0 _ h1 ->
modifies1 write h0 h1 /\
as_seq h1 write ==
Seq.repeat_blocks #a #(Seq.lseq b (v blen)) (v blocksize) (as_seq h0 inp) spec_f spec_l (as_seq h0 write))
open FStar.Mul
(*
(** Fills a buffer block by block using a function with an accumulator *)
inline_for_extraction
val fill_blocks_:
#t:Type0
-> h0:mem
-> len:size_t
-> n:size_t{v n * v len <= max_size_t}
-> output:lbuffer t (n *! len)
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot
(l:B.loc{B.loc_disjoint l (loc output) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}))
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1) & Seq.lseq t (v len)))
-> impl:(i:size_t{v i < v n} -> block:lbuffer t len -> Stack unit
(requires fun h1 ->
live h1 block /\
loc output `B.loc_includes` loc block /\
modifies (B.loc_union (footprint (v i)) (loc output)) h0 h1)
(ensures fun h1 _ h2 ->
let s, b = spec h0 (v i) (refl h1 (v i)) in
footprint (v i + 1) `B.loc_includes` footprint (v i) /\
B.modifies (B.loc_union (footprint (v i + 1)) (loc block)) h1 h2 /\
refl h2 (v i + 1) == s /\ as_seq h2 block == b)) ->
Stack unit
(requires fun h -> h0 == h /\ live h output)
(ensures fun _ _ h1 ->
let s, o = Seq.generate_blocks (v len) (v n) a_spec (spec h0) (refl h0 0) in
B.modifies (B.loc_union (footprint (v n)) (loc output)) h0 h1 /\
refl h1 (v n) == s /\
as_seq #_ #t h1 (gsub output (size 0) (n *! len)) == o)
*)
#set-options "--z3rlimit 150"
(** Fills a buffer block by block using a function with an accumulator *)
inline_for_extraction
val fill_blocks:
#t:Type0
-> h0:mem
-> len:size_t
-> n:size_t{v n * v len <= max_size_t}
-> output:lbuffer t (n *! len)
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot
(l:B.loc{B.loc_disjoint l (loc output) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}))
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1) & Seq.lseq t (v len)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires fun h1 ->
(v i + 1) * v len <= max_size_t /\
modifies (footprint (v i) |+| loc (gsub output 0ul (i *! len))) h0 h1)
(ensures fun h1 _ h2 ->
(let block = gsub output (i *! len) len in
let s, b = spec h0 (v i) (refl h1 (v i)) in
footprint (v i + 1) `B.loc_includes` footprint (v i) /\
B.modifies (B.loc_union (footprint (v i + 1)) (loc block)) h1 h2 /\
refl h2 (v i + 1) == s /\ as_seq h2 block == b))) ->
Stack unit
(requires fun h -> h0 == h /\ live h output)
(ensures fun _ _ h1 ->
B.modifies (B.loc_union (footprint (v n)) (loc output)) h0 h1 /\
(let s, o = Seq.generate_blocks (v len) (v n) (v n) a_spec (spec h0) (refl h0 0) in
refl h1 (v n) == s /\
as_seq #_ #t h1 output == o))
(** Fills a buffer block by block using a function without an accumulator *)
inline_for_extraction
val fill_blocks_simple:
#t:Type0
-> h0:mem
-> bs:size_t{v bs > 0}
-> n:size_t{v bs * v n <= max_size_t}
-> output:lbuffer t (bs *! n)
-> spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq t (v bs)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires fun h1 ->
FStar.Math.Lemmas.lemma_mult_le_right (v bs) (v i) (v n);
(v i + 1) * v bs <= max_size_t /\
modifies (loc (gsub output 0ul (i *! bs))) h0 h1)
(ensures fun h1 _ h2 ->
(let block = gsub output (i *! bs) bs in
let ob = spec h0 (v i) in
B.modifies (loc block) h1 h2 /\
as_seq h2 block == ob))) ->
Stack unit
(requires fun h -> h0 == h /\ live h output)
(ensures fun _ _ h1 -> modifies1 output h0 h1 /\
as_seq #_ #t h1 output == Sequence.generate_blocks_simple (v bs) (v n) (v n) (spec h0))
(** Fill a buffer with a total function *)
inline_for_extraction
val fillT:
#a:Type
-> clen:size_t
-> o:lbuffer a clen
-> spec_f:(i:size_nat{i < v clen} -> a)
-> f:(i:size_t{v i < v clen} -> r:a{r == spec_f (size_v i)}) ->
Stack unit
(requires fun h0 -> live h0 o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == Seq.createi #a (v clen) spec_f)
(** Fill a buffer with a stateful function *)
inline_for_extraction
val fill:
#a:Type
-> h0:mem
-> clen:size_t
-> o:lbuffer a clen
-> spec:(mem -> GTot(i:size_nat{i < v clen} -> a))
-> impl:(i:size_t{v i < v clen} -> Stack a
(requires fun h -> modifies1 (gsub o 0ul i) h0 h)
(ensures fun h r h' -> h == h' /\
r == spec h0 (v i)))
-> Stack unit
(requires fun h -> h == h0 /\ live h0 o)
(ensures fun h _ h' ->
modifies1 o h h' /\
as_seq h' o == Seq.createi #a (v clen) (spec h0)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b1: Lib.Buffer.lbuffer_t t1 a1 clen1 -> b2: Lib.Buffer.lbuffer_t t2 a2 clen2 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.buftype",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer_t",
"Prims.l_or",
"Lib.Buffer.disjoint",
"Prims.l_and",
"Prims.eq2",
"Lib.Buffer.buffer_t",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Prims.logical"
] | [] | false | false | false | false | true | let eq_or_disjoint
(#t1 #t2: buftype)
(#a1 #a2: Type)
(#clen1 #clen2: size_t)
(b1: lbuffer_t t1 a1 clen1)
(b2: lbuffer_t t2 a2 clen2)
=
| disjoint b1 b2 \/ (t1 == t2 /\ a1 == a2 /\ clen1 == clen2 /\ b1 == b2) | false |
|
Lib.Buffer.fsti | Lib.Buffer.witnessed | val witnessed : b: Lib.Buffer.glbuffer a len -> s: Lib.Sequence.lseq a (Lib.IntTypes.v len) -> Type0 | let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 383,
"start_col": 0,
"start_line": 382
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.glbuffer a len -> s: Lib.Sequence.lseq a (Lib.IntTypes.v len) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.glbuffer",
"Lib.Sequence.lseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Monotonic.Buffer.witnessed",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Lib.Buffer.cpred"
] | [] | false | false | false | false | true | let witnessed (#a: Type0) (#len: size_t) (b: glbuffer a len) (s: Seq.lseq a (v len)) =
| B.witnessed (CB.as_mbuf b) (cpred s) | false |
|
Lib.Buffer.fsti | Lib.Buffer.loop2_inv | val loop2_inv
(#b0: Type)
(#blen0: size_t)
(#b1: Type)
(#blen1: size_t)
(h0: mem)
(n: size_t)
(write0: lbuffer b0 blen0)
(write1: lbuffer b1 blen1)
(spec:
(mem
-> GTot
(i: size_nat{i < v n} -> ((Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | val loop2_inv
(#b0: Type)
(#blen0: size_t)
(#b1: Type)
(#blen1: size_t)
(h0: mem)
(n: size_t)
(write0: lbuffer b0 blen0)
(write1: lbuffer b1 blen1)
(spec:
(mem
-> GTot
(i: size_nat{i < v n} -> ((Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | let loop2_inv
(#b0:Type)
(#blen0:size_t)
(#b1:Type)
(#blen1:size_t)
(h0:mem)
(n:size_t)
(write0:lbuffer b0 blen0)
(write1:lbuffer b1 blen1)
(spec:(mem -> GTot (i:size_nat{i < v n}
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1))
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies2 write0 write1 h0 h /\
(let s0, s1 = Loop.repeati i (spec h0) (as_seq h0 write0, as_seq h0 write1) in
as_seq h write0 == s0 /\ as_seq h write1 == s1) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 743,
"start_col": 0,
"start_line": 725
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1
let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s)
(** Allocate a stack fixed-length mutable buffer and initialize it to value [init] *)
inline_for_extraction
val create:
#a:Type0
-> len:size_t
-> init:a ->
StackInline (lbuffer a len)
(requires fun h0 -> v len > 0)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create (v len) init))
#set-options "--max_fuel 1"
(** Allocate a stack fixed-length mutable buffer initialized to a list *)
inline_for_extraction
val createL:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
StackInline (lbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.alloca_of_list_pre #a init)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.of_list init))
(** Allocate a global fixed-length const immutable buffer initialized to value [init] *)
inline_for_extraction
val createL_global:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
ST (glbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.gcmalloc_of_list_pre #a HyperStack.root init)
(ensures fun h0 b h1 -> global_allocated b h0 h1 (Seq.of_list init) /\
recallable b /\
witnessed b (Seq.of_list init))
(** Allocate a global fixed-length mutable buffer initialized to value [init] *)
inline_for_extraction
val createL_mglobal: #a:Type0 -> init:list a ->
ST (buffer a)
(requires fun h0 -> normalize (FStar.List.Tot.length init <= max_size_t))
(ensures fun h0 b h1 ->
B.frameOf b == HyperStack.root /\ B.recallable b /\
alloc_post_mem_common (b <: buffer a) h0 h1 (FStar.Seq.seq_of_list init) /\
length b == normalize_term (FStar.List.Tot.length init))
#set-options "--max_fuel 0"
(** Recall the liveness and contents of a global immutable buffer *)
inline_for_extraction
val recall_contents:
#a:Type0
-> #len:size_t{v len <= max_size_t}
-> b:glbuffer a len
-> s:Seq.lseq a (v len) ->
ST unit
(requires fun h0 -> (live h0 b \/ recallable b) /\ witnessed b s)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ as_seq h0 b == s)
(** Copy a buffer into a mutable buffer *)
inline_for_extraction
val copy:
#t:buftype
-> #a:Type
-> #len:size_t
-> o:lbuffer a len
-> i:lbuffer_t t a len ->
Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint i o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == as_seq h0 i)
(**
* Set all elements of a mutable buffer to a specific value
*
* WARNING: don't rely on the extracted implementation for secure erasure,
* C compilers may remove optimize it away.
*)
inline_for_extraction
val memset:
#a:Type
-> #blen:size_t
-> b:lbuffer a blen
-> w:a
-> len:size_t{v len <= v blen} ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 (gsub b 0ul len) == Seq.create (v len) w /\
as_seq h1 (gsub b len (blen -! len)) ==
as_seq h0 (gsub b len (blen -! len)))
(** Copy a buffer into a sub-buffer of a mutable buffer *)
inline_for_extraction
val update_sub:
#t:buftype
-> #a:Type
-> #len:size_t
-> dst:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> src:lbuffer_t t a n ->
Stack unit
(requires fun h -> live h dst /\ live h src /\ disjoint dst src)
(ensures fun h0 _ h1 ->
modifies1 dst h0 h1 /\
as_seq h1 dst == Seq.update_sub (as_seq h0 dst) (v start) (v n) (as_seq h0 src))
(** Update a mutable buffer in-place by applying a function on a sub-buffer of it *)
inline_for_extraction
val update_sub_f:
#a:Type
-> #len:size_t
-> h0:mem
-> buf:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> spec:(mem -> GTot (Seq.lseq a (v n)))
-> f:(unit -> Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 ->
(let b = gsub buf start n in
modifies (loc b) h0 h1 /\
as_seq h1 b == spec h0))) ->
Stack unit
(requires fun h -> h0 == h /\ live h buf)
(ensures fun h0 _ h1 ->
modifies (loc buf) h0 h1 /\
as_seq h1 buf == Seq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) (spec h0))
(** Copy two buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat2:
#t0:buftype
-> #t1:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> s:lbuffer a (len0 +! len1)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s /\
disjoint s s0 /\ disjoint s s1)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (as_seq h0 s0) (as_seq h0 s1))
(** Copy three buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat3:
#t0:buftype
-> #t1:buftype
-> #t2:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> len2:size_t{v len0 + v len1 + v len2 <= max_size_t}
-> s2:lbuffer_t t2 a len2
-> s:lbuffer a (len0 +! len1 +! len2)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s2 /\ live h s /\
disjoint s s0 /\ disjoint s s1 /\ disjoint s s2)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (Seq.concat (as_seq h0 s0) (as_seq h0 s1)) (as_seq h0 s2))
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> n:size_t
-> buf:lbuffer a len
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec2:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #len1:size_t
-> #len2:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies2 buf1 buf2 h0 h)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec3:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #a3:Type0
-> #len1:size_t
-> #len2:size_t
-> #len3:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> buf3:lbuffer a3 len3
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies3 buf1 buf2 buf3 h0 h)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2 /\ live h0 buf3)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_range_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> start:size_t
-> n:size_t{v start + v n <= max_size_t}
-> buf:lbuffer a len
-> impl: (i:size_t{v start <= v i /\ v i < v start + v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
let loop_inv
(h0:mem)
(n:size_t)
(a_spec:(i:size_nat{i <= v n} -> Type))
(refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i)))
(footprint:(i:size_nat{i <= v n} -> GTot B.loc))
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies (footprint i) h0 h /\
refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0)
(**
* A generalized loop combinator paremetrized by its state (e.g. an accumulator)
*
* Arguments:
* - [h0] the heap when entering the loop
* - [n] the number of iterations
* - [a_spec] the type for the specification state (may depend on the loop index)
* - [refl] a ghost function that reflects the Low* state in an iteration as [a_spec]
* - [footprint] locations modified by the loop (may depend on the loop index)
* - [spec] a specification of how the body of the loop modifies the state
* - [impl] the body of the loop as a Stack function
*)
inline_for_extraction
val loop:
h0:mem
-> n:size_t
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot B.loc)
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_inv h0 n a_spec refl footprint spec (v n) h1)
let loop_refl_inv
(h0:mem)
(n:size_t)
(a_spec: Type)
(refl:(mem -> GTot a_spec))
(footprint:B.loc)
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec)))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies footprint h0 h /\
refl h == Loop.repeati i (spec h0) (refl h0)
inline_for_extraction
val loop_refl:
h0:mem
-> n:size_t
-> a_spec:Type
-> refl:(mem -> GTot a_spec)
-> footprint:Ghost.erased B.loc
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_refl_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_refl_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_refl_inv h0 n a_spec refl footprint spec (v n) h1)
let loop1_inv
(h0:mem)
(n:size_t)
(b: Type)
(blen: size_t)
(write:lbuffer b blen)
(spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies1 write h0 h /\
as_seq h write == Loop.repeati i (spec h0) (as_seq h0 write)
(** Loop combinator specialized to modifying a single buffer [write] *)
inline_for_extraction
val loop1:
#b:Type
-> #blen:size_t
-> h0:mem
-> n:size_t
-> write:lbuffer b blen
-> spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop1_inv h0 n b blen write spec (v i))
(ensures fun _ _ -> loop1_inv h0 n b blen write spec (v i + 1))) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun _ _ -> loop1_inv h0 n b blen write spec (v n)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
n: Lib.IntTypes.size_t ->
write0: Lib.Buffer.lbuffer b0 blen0 ->
write1: Lib.Buffer.lbuffer b1 blen1 ->
spec:
(_: FStar.Monotonic.HyperStack.mem
-> Prims.GTot
(
i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n} ->
_:
(Lib.Sequence.lseq b0 (Lib.IntTypes.v blen0) *
Lib.Sequence.lseq b1 (Lib.IntTypes.v blen1))
-> Lib.Sequence.lseq b0 (Lib.IntTypes.v blen0) *
Lib.Sequence.lseq b1 (Lib.IntTypes.v blen1))) ->
i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} ->
h: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.Pervasives.Native.tuple2",
"Lib.Sequence.lseq",
"Prims.op_LessThanOrEqual",
"Prims.l_and",
"Lib.Buffer.modifies2",
"Prims.eq2",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.logical",
"Lib.LoopCombinators.repeati",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | false | true | let loop2_inv
(#b0: Type)
(#blen0: size_t)
(#b1: Type)
(#blen1: size_t)
(h0: mem)
(n: size_t)
(write0: lbuffer b0 blen0)
(write1: lbuffer b1 blen1)
(spec:
(mem
-> GTot
(i: size_nat{i < v n} -> ((Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))
-> (Seq.lseq b0 (v blen0)) & (Seq.lseq b1 (v blen1)))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 =
| modifies2 write0 write1 h0 h /\
(let s0, s1 = Loop.repeati i (spec h0) (as_seq h0 write0, as_seq h0 write1) in
as_seq h write0 == s0 /\ as_seq h write1 == s1) | false |
Lib.Buffer.fsti | Lib.Buffer.loop1_inv | val loop1_inv
(h0: mem)
(n: size_t)
(b: Type)
(blen: size_t)
(write: lbuffer b blen)
(spec: (mem -> GTot (i: size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | val loop1_inv
(h0: mem)
(n: size_t)
(b: Type)
(blen: size_t)
(write: lbuffer b blen)
(spec: (mem -> GTot (i: size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | let loop1_inv
(h0:mem)
(n:size_t)
(b: Type)
(blen: size_t)
(write:lbuffer b blen)
(spec:(mem -> GTot (i:size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies1 write h0 h /\
as_seq h write == Loop.repeati i (spec h0) (as_seq h0 write) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 707,
"start_col": 0,
"start_line": 695
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1
let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s)
(** Allocate a stack fixed-length mutable buffer and initialize it to value [init] *)
inline_for_extraction
val create:
#a:Type0
-> len:size_t
-> init:a ->
StackInline (lbuffer a len)
(requires fun h0 -> v len > 0)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create (v len) init))
#set-options "--max_fuel 1"
(** Allocate a stack fixed-length mutable buffer initialized to a list *)
inline_for_extraction
val createL:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
StackInline (lbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.alloca_of_list_pre #a init)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.of_list init))
(** Allocate a global fixed-length const immutable buffer initialized to value [init] *)
inline_for_extraction
val createL_global:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
ST (glbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.gcmalloc_of_list_pre #a HyperStack.root init)
(ensures fun h0 b h1 -> global_allocated b h0 h1 (Seq.of_list init) /\
recallable b /\
witnessed b (Seq.of_list init))
(** Allocate a global fixed-length mutable buffer initialized to value [init] *)
inline_for_extraction
val createL_mglobal: #a:Type0 -> init:list a ->
ST (buffer a)
(requires fun h0 -> normalize (FStar.List.Tot.length init <= max_size_t))
(ensures fun h0 b h1 ->
B.frameOf b == HyperStack.root /\ B.recallable b /\
alloc_post_mem_common (b <: buffer a) h0 h1 (FStar.Seq.seq_of_list init) /\
length b == normalize_term (FStar.List.Tot.length init))
#set-options "--max_fuel 0"
(** Recall the liveness and contents of a global immutable buffer *)
inline_for_extraction
val recall_contents:
#a:Type0
-> #len:size_t{v len <= max_size_t}
-> b:glbuffer a len
-> s:Seq.lseq a (v len) ->
ST unit
(requires fun h0 -> (live h0 b \/ recallable b) /\ witnessed b s)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ as_seq h0 b == s)
(** Copy a buffer into a mutable buffer *)
inline_for_extraction
val copy:
#t:buftype
-> #a:Type
-> #len:size_t
-> o:lbuffer a len
-> i:lbuffer_t t a len ->
Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint i o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == as_seq h0 i)
(**
* Set all elements of a mutable buffer to a specific value
*
* WARNING: don't rely on the extracted implementation for secure erasure,
* C compilers may remove optimize it away.
*)
inline_for_extraction
val memset:
#a:Type
-> #blen:size_t
-> b:lbuffer a blen
-> w:a
-> len:size_t{v len <= v blen} ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 (gsub b 0ul len) == Seq.create (v len) w /\
as_seq h1 (gsub b len (blen -! len)) ==
as_seq h0 (gsub b len (blen -! len)))
(** Copy a buffer into a sub-buffer of a mutable buffer *)
inline_for_extraction
val update_sub:
#t:buftype
-> #a:Type
-> #len:size_t
-> dst:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> src:lbuffer_t t a n ->
Stack unit
(requires fun h -> live h dst /\ live h src /\ disjoint dst src)
(ensures fun h0 _ h1 ->
modifies1 dst h0 h1 /\
as_seq h1 dst == Seq.update_sub (as_seq h0 dst) (v start) (v n) (as_seq h0 src))
(** Update a mutable buffer in-place by applying a function on a sub-buffer of it *)
inline_for_extraction
val update_sub_f:
#a:Type
-> #len:size_t
-> h0:mem
-> buf:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> spec:(mem -> GTot (Seq.lseq a (v n)))
-> f:(unit -> Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 ->
(let b = gsub buf start n in
modifies (loc b) h0 h1 /\
as_seq h1 b == spec h0))) ->
Stack unit
(requires fun h -> h0 == h /\ live h buf)
(ensures fun h0 _ h1 ->
modifies (loc buf) h0 h1 /\
as_seq h1 buf == Seq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) (spec h0))
(** Copy two buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat2:
#t0:buftype
-> #t1:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> s:lbuffer a (len0 +! len1)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s /\
disjoint s s0 /\ disjoint s s1)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (as_seq h0 s0) (as_seq h0 s1))
(** Copy three buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat3:
#t0:buftype
-> #t1:buftype
-> #t2:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> len2:size_t{v len0 + v len1 + v len2 <= max_size_t}
-> s2:lbuffer_t t2 a len2
-> s:lbuffer a (len0 +! len1 +! len2)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s2 /\ live h s /\
disjoint s s0 /\ disjoint s s1 /\ disjoint s s2)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (Seq.concat (as_seq h0 s0) (as_seq h0 s1)) (as_seq h0 s2))
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> n:size_t
-> buf:lbuffer a len
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec2:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #len1:size_t
-> #len2:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies2 buf1 buf2 h0 h)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec3:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #a3:Type0
-> #len1:size_t
-> #len2:size_t
-> #len3:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> buf3:lbuffer a3 len3
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies3 buf1 buf2 buf3 h0 h)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2 /\ live h0 buf3)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_range_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> start:size_t
-> n:size_t{v start + v n <= max_size_t}
-> buf:lbuffer a len
-> impl: (i:size_t{v start <= v i /\ v i < v start + v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
let loop_inv
(h0:mem)
(n:size_t)
(a_spec:(i:size_nat{i <= v n} -> Type))
(refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i)))
(footprint:(i:size_nat{i <= v n} -> GTot B.loc))
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies (footprint i) h0 h /\
refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0)
(**
* A generalized loop combinator paremetrized by its state (e.g. an accumulator)
*
* Arguments:
* - [h0] the heap when entering the loop
* - [n] the number of iterations
* - [a_spec] the type for the specification state (may depend on the loop index)
* - [refl] a ghost function that reflects the Low* state in an iteration as [a_spec]
* - [footprint] locations modified by the loop (may depend on the loop index)
* - [spec] a specification of how the body of the loop modifies the state
* - [impl] the body of the loop as a Stack function
*)
inline_for_extraction
val loop:
h0:mem
-> n:size_t
-> a_spec:(i:size_nat{i <= v n} -> Type)
-> refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i))
-> footprint:(i:size_nat{i <= v n} -> GTot B.loc)
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1)))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_inv h0 n a_spec refl footprint spec (v n) h1)
let loop_refl_inv
(h0:mem)
(n:size_t)
(a_spec: Type)
(refl:(mem -> GTot a_spec))
(footprint:B.loc)
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec)))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies footprint h0 h /\
refl h == Loop.repeati i (spec h0) (refl h0)
inline_for_extraction
val loop_refl:
h0:mem
-> n:size_t
-> a_spec:Type
-> refl:(mem -> GTot a_spec)
-> footprint:Ghost.erased B.loc
-> spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec -> a_spec))
-> impl:(i:size_t{v i < v n} -> Stack unit
(requires loop_refl_inv h0 n a_spec refl footprint spec (v i))
(ensures fun _ _ h -> loop_refl_inv h0 n a_spec refl footprint spec (v i + 1) h)) ->
Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 -> loop_refl_inv h0 n a_spec refl footprint spec (v n) h1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
n: Lib.IntTypes.size_t ->
b: Type0 ->
blen: Lib.IntTypes.size_t ->
write: Lib.Buffer.lbuffer b blen ->
spec:
(_: FStar.Monotonic.HyperStack.mem
-> Prims.GTot
(
i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n} ->
_: Lib.Sequence.lseq b (Lib.IntTypes.v blen)
-> Lib.Sequence.lseq b (Lib.IntTypes.v blen))) ->
i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} ->
h: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Sequence.lseq",
"Prims.op_LessThanOrEqual",
"Prims.l_and",
"Lib.Buffer.modifies1",
"Prims.eq2",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.LoopCombinators.repeati"
] | [] | false | false | false | false | true | let loop1_inv
(h0: mem)
(n: size_t)
(b: Type)
(blen: size_t)
(write: lbuffer b blen)
(spec: (mem -> GTot (i: size_nat{i < v n} -> Seq.lseq b (v blen) -> Seq.lseq b (v blen))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 =
| modifies1 write h0 h /\ as_seq h write == Loop.repeati i (spec h0) (as_seq h0 write) | false |
Hacl.Streaming.Keccak.fst | Hacl.Streaming.Keccak.hash_len | val hash_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
not (is_shake_ a) /\
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.hash_length a)) | val hash_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
not (is_shake_ a) /\
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.hash_length a)) | let hash_len a s =
let a = get_alg a s in
Hacl.Hash.SHA3.hash_len a | {
"file_name": "code/streaming/Hacl.Streaming.Keccak.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 343,
"start_col": 0,
"start_line": 341
} | module Hacl.Streaming.Keccak
open FStar.HyperStack.ST
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
open Hacl.Streaming.Types
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
inline_for_extraction noextract
let uint64 = Lib.IntTypes.uint64
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg
/// This is a dedicated streaming API for the Keccak construction. The reason we
/// are not piggybacking on Hacl.Streaming.MD is that we want a *single* piece
/// of code that can deal with all 6 variants at runtime, as opposed to a
/// meta-programmed version that requires six instantiations each for each one
/// of the Keccak algorithms. Notably, this means that we keep the rate at
/// run-time (relying on the key), and that we request the outputByteLen for the
/// finish function.
inline_for_extraction noextract
let alg = keccak_alg
unfold let coerce (#b #a:Type) (x:a{a == b}) : b = x
inline_for_extraction noextract
let update_multi_s (a : alg) acc (prevlen : nat) input =
Agile.update_multi a acc () input
noextract
let update_multi_zero (a : alg) acc (prevlen : nat) :
Lemma(update_multi_s a acc prevlen S.empty == acc) = Spec.Hash.Lemmas.update_multi_zero a acc
// TODO: this is the fourth copy of this lemma!! why?!
#push-options "--ifuel 1"
noextract
let update_multi_associative (a : alg) acc (prevlen1 prevlen2 : nat)
(input1 input2 : S.seq uint8) :
Lemma
(requires (
prevlen1 % U32.v (D.block_len a) = 0 /\
S.length input1 % U32.v (D.block_len a) = 0 /\
S.length input2 % U32.v (D.block_len a) = 0 /\
prevlen2 = prevlen1 + S.length input1))
(ensures (
let input = S.append input1 input2 in
S.length input % U32.v (D.block_len a) = 0 /\
prevlen2 % U32.v (D.block_len a) = 0 /\
update_multi_s a (update_multi_s a acc prevlen1 input1) prevlen2 input2 ==
update_multi_s a acc prevlen1 input)) =
Spec.Hash.Lemmas.update_multi_associative a acc input1 input2
#pop-options
inline_for_extraction noextract
let singleton #t (x: t) = y:t { y == x }
// Pretty C name
let hash_buf = hash_alg & B.buffer uint64
let hash_buf2 = hash_buf & hash_buf
inline_for_extraction noextract
let stateful_keccak: stateful alg =
Stateful
(* s: *) (fun (a: alg) ->
singleton a & b:B.buffer uint64 { B.len b == 25ul })
(* footprint: *) (fun #_ h (_, s) ->
B.loc_addr_of_buffer s)
(* freeable: *) (fun #_ h (_, s) ->
B.freeable s)
(* invariant: *) (fun #_ h (_, s) ->
B.live h s)
(* t: *) (fun _ ->
s:S.seq uint64 { S.length s == 25 })
(* v: *) (fun _ h (a, s) ->
B.as_seq h s)
(* invariant_loc_in_footprint: *) (fun #_ h (_, s) ->
())
(* frame_invariant: *) (fun #_ l (_, s) h0 h1 ->
())
(* frame_freeable: *) (fun #_ l (_, s) h0 h1 ->
())
(* alloca: *) (fun (a: alg) ->
a, B.alloca (Lib.IntTypes.u64 0) 25ul)
(* malloc: *) (fun a r ->
a, B.malloc r (Lib.IntTypes.u64 0) 25ul)
(* free: *) (fun _ (_, s) ->
B.free s)
(* copy: *) (fun _ (a, s_src) (a', s_dst) ->
B.blit s_src 0ul s_dst 0ul 25ul)
noextract inline_for_extraction
let is_shake_ a = a = Shake128 || a = Shake256
inline_for_extraction noextract
let hacl_keccak (a: G.erased alg): block alg =
Block
Erased
stateful_keccak (* state *)
(stateful_unused alg) (* key *)
Lib.IntTypes.(x:size_t { v x > 0 }) (* output_length_t *)
(fun _ ->
[@inline_let]
let max = Lib.IntTypes.(ones U64 PUB) in
assert (forall (a: alg). Hacl.Hash.Definitions.max_input_len64 a == max);
max) (* max_input_len *)
(fun a l -> if is_shake_ a then Lib.IntTypes.v l else Spec.Hash.Definitions.hash_length a) (* output_length *)
Hacl.Hash.SHA3.block_len (* block_len *)
Hacl.Hash.SHA3.block_len (* blocks_state_len *)
(fun _ -> 0ul) (* init_input_len *)
(* init_input_s *)
(fun _ _ -> S.empty)
(* init_s *)
(fun a _ -> Spec.Agile.Hash.init a)
(* update_multi_s *)
(fun a acc prevlen blocks ->
update_multi_s a acc prevlen blocks)
(* update_last_s *)
(fun a acc prevlen input -> Spec.Hash.Incremental.(update_last a acc () input))
(* finish_s *)
(fun a _ acc l -> Spec.Agile.Hash.finish a acc (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(fun a _ s l -> Spec.Agile.Hash.(hash' a s (if is_shake_ a then (Lib.IntTypes.v l) else ())))
(* update_multi_zero *)
(fun a h prevlen -> update_multi_zero a h prevlen)
(* update_multi_associative *)
(fun a acc prevlen1 prevlen2 input1 input2 ->
update_multi_associative a acc prevlen1 prevlen2 input1 input2)
(* spec_is_incremental *)
(fun a _ input l ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input (if is_shake_ a then (Lib.IntTypes.v l) else ()))
(* index_of_state *)
(fun _ (a, _) -> a)
(* init *)
(fun _ _ _ (a, s) -> Hacl.Hash.SHA3.init a s)
(* update_multi *)
(fun _ (a, s) _ blocks len ->
Hacl.Hash.SHA3.update_multi a s () blocks (len `U32.div` Hacl.Hash.SHA3.(block_len a)))
(* update_last *)
(fun _ (a, s) _ last last_len ->
Hacl.Hash.SHA3.update_last a s () last last_len)
(* finish *)
(fun _ _ (a, s) dst l ->
Hacl.Hash.SHA3.(finish_keccak a s dst l))
// For pretty names in C
let state_t = F.state_s' (hacl_keccak SHA3_256) SHA3_256
let sha3_state a = singleton a & b:B.buffer uint64 { B.len b == 25ul }
let get_alg (a: G.erased alg) =
F.index_of_state (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let malloc (a: alg) =
F.malloc (hacl_keccak a) a (sha3_state a) (G.erased unit)
let free (a: G.erased alg) =
F.free (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let copy (a: G.erased alg) =
F.copy (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let reset (a: G.erased alg) =
F.reset (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
let update (a: G.erased alg) =
F.update (hacl_keccak a) a (sha3_state (G.reveal a)) (G.erased unit)
private
let digest_ (a: alg) =
F.digest #alg (hacl_keccak a) a (sha3_state a) (G.erased unit)
open Hacl.Streaming.Functor
// Unfortunate copy-paste since there are small variations (error code, output length)
val digest:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
Stack error_code
(requires fun h0 ->
(not (is_shake a) ==> B.length dst == Spec.Hash.Definitions.hash_length a) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
match r with
| Success ->
not (is_shake a) /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (Spec.Agile.Hash.hash a (seen c i h0 s)) /\
preserves_freeable c i s h0 h1)
| InvalidAlgorithm ->
is_shake a
| _ ->
False))
let digest a state output =
let a = get_alg a state in
if (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else begin
digest_ a state output (Hacl.Hash.SHA3.hash_len a);
Success
end
// Unfortunate copy-paste since we are returning an error code
val squeeze:
a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
dst:B.buffer uint8 ->
l:Lib.IntTypes.size_t ->
Stack error_code
(requires fun h0 ->
(is_shake a ==> B.length dst == Lib.IntTypes.v l) /\
invariant c i h0 s /\
B.live h0 dst /\
B.(loc_disjoint (loc_buffer dst) (footprint c i h0 s)))
(ensures fun h0 r h1 ->
let _ = allow_inversion error_code in
match r with
| Success ->
is_shake a /\
l <> 0ul /\
invariant c i h1 s /\
seen c i h0 s == seen c i h1 s /\
reveal_key c i h1 s == reveal_key c i h0 s /\
footprint c i h0 s == footprint c i h1 s /\
B.(modifies (loc_union (loc_buffer dst) (footprint c i h0 s)) h0 h1) /\ (
seen_bounded c i h0 s;
S.equal (B.as_seq h1 dst) (c.spec_s i (reveal_key c i h0 s) (seen c i h0 s) l)) /\
preserves_freeable c i s h0 h1
| InvalidAlgorithm ->
not (is_shake a)
| InvalidLength ->
l = 0ul
| _ ->
False))
let squeeze a s dst l =
let a = get_alg a s in
if not (a = Shake128 || a = Shake256) then
InvalidAlgorithm
else if l = 0ul then
InvalidLength
else begin
digest_ a s dst l;
Success
end
val block_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.block_length a /\
Lib.IntTypes.v r == Spec.Hash.Definitions.rate a / 8))
let block_len a s =
let a = get_alg a s in
Hacl.Hash.SHA3.block_len a
val hash_len: a:G.erased alg -> (
let c = hacl_keccak a in
let a = G.reveal a in
let i = a in
let t = sha3_state a in
let t' = G.erased unit in
s:state c i t t' ->
Stack Lib.IntTypes.size_t
(requires fun h0 ->
not (is_shake_ a) /\
invariant c i h0 s)
(ensures fun h0 r h1 ->
B.(modifies loc_none h0 h1) /\
Lib.IntTypes.v r == Spec.Hash.Definitions.hash_length a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Types.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Keccak.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Functor",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | a: FStar.Ghost.erased Hacl.Streaming.Keccak.alg
-> (let c = Hacl.Streaming.Keccak.hacl_keccak a in
let a = FStar.Ghost.reveal a in
let i = a in
let t = Hacl.Streaming.Keccak.sha3_state a in
let t' = FStar.Ghost.erased Prims.unit in
s: Hacl.Streaming.Functor.state c i t t' -> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.Streaming.Keccak.alg",
"Hacl.Streaming.Functor.state",
"Hacl.Streaming.Keccak.hacl_keccak",
"FStar.Ghost.reveal",
"Hacl.Streaming.Keccak.sha3_state",
"Prims.unit",
"Hacl.Hash.SHA3.hash_len",
"Lib.IntTypes.size_t",
"Hacl.Streaming.Keccak.get_alg"
] | [] | false | false | false | false | false | let hash_len a s =
| let a = get_alg a s in
Hacl.Hash.SHA3.hash_len a | false |
Lib.Buffer.fsti | Lib.Buffer.loop_inv | val loop_inv
(h0: mem)
(n: size_t)
(a_spec: (i: size_nat{i <= v n} -> Type))
(refl: (mem -> i: size_nat{i <= v n} -> GTot (a_spec i)))
(footprint: (i: size_nat{i <= v n} -> GTot B.loc))
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | val loop_inv
(h0: mem)
(n: size_t)
(a_spec: (i: size_nat{i <= v n} -> Type))
(refl: (mem -> i: size_nat{i <= v n} -> GTot (a_spec i)))
(footprint: (i: size_nat{i <= v n} -> GTot B.loc))
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 | let loop_inv
(h0:mem)
(n:size_t)
(a_spec:(i:size_nat{i <= v n} -> Type))
(refl:(mem -> i:size_nat{i <= v n} -> GTot (a_spec i)))
(footprint:(i:size_nat{i <= v n} -> GTot B.loc))
(spec:(mem -> GTot (i:size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i:size_nat{i <= v n})
(h:mem):
Type0
=
modifies (footprint i) h0 h /\
refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0) | {
"file_name": "lib/Lib.Buffer.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 636,
"start_col": 0,
"start_line": 624
} | module Lib.Buffer
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.RawIntTypes
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module CB = LowStar.ConstBuffer
module LMB = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module Seq = Lib.Sequence
module ByteSeq = Lib.ByteSequence
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1"
type buftype =
| MUT
| IMMUT
| CONST
inline_for_extraction
let buffer_t (t:buftype) (a:Type0) =
match t with
| IMMUT -> IB.ibuffer a
| MUT -> B.buffer a
| CONST -> CB.const_buffer a
(** Mutable buffer. Extracted as `a*` *)
unfold let buffer (a:Type0) = buffer_t MUT a
(** Immutable buffer. Extracted as `a*`. Enjoys nice properties for recalling contents. *)
unfold let ibuffer (a:Type0) = buffer_t IMMUT a
(** Const buffer. Either one of the two above. Extracts as `const a*`. *)
unfold let cbuffer (a:Type0) = buffer_t CONST a
(** Global buffers are const immutable *)
unfold let gbuffer (a:Type0) = c:cbuffer a{CB.qual_of c == CB.IMMUTABLE}
let length (#t:buftype) (#a:Type0) (b:buffer_t t a) =
match t with
| MUT -> B.length (b <: buffer a)
| IMMUT -> IB.length (b <: ibuffer a)
| CONST -> CB.length (b <: cbuffer a)
inline_for_extraction
let to_const #a #t (b:buffer_t t a) : r:cbuffer a {length r == length b}=
match t with
| MUT -> CB.of_buffer (b <: buffer a)
| IMMUT -> CB.of_ibuffer (b <: ibuffer a)
| CONST -> b <: cbuffer a
let const_to_buffer #a (b:cbuffer a{CB.qual_of b == CB.MUTABLE}) : r:buffer a{length r == length b} =
CB.to_buffer b
let const_to_ibuffer #a (b:cbuffer a{CB.qual_of b == CB.IMMUTABLE}) : r:ibuffer a{length r == length b} =
CB.to_ibuffer b
inline_for_extraction
let lbuffer_t (t:buftype) (a:Type0) (len:size_t) =
b:buffer_t t a{length #t #a b == v len}
unfold let lbuffer (a:Type0) (len:size_t) = lbuffer_t MUT a len
unfold let ilbuffer (a:Type0) (len:size_t) = lbuffer_t IMMUT a len
unfold let clbuffer (a:Type0) (len:size_t) = lbuffer_t CONST a len
unfold let glbuffer (a:Type0) (len:size_t) = c:clbuffer a len{CB.qual_of #a c == CB.IMMUTABLE}
let const_to_lbuffer #a #len
(b:clbuffer a len{CB.qual_of (b <: cbuffer a) == CB.MUTABLE}) : lbuffer a len =
const_to_buffer #a b
let const_to_ilbuffer #a #len (b:glbuffer a len) : ilbuffer a len =
const_to_ibuffer #a b
unfold let null (#t : buftype) (a : Type0) : buffer_t t a =
match t with
| IMMUT -> IB.inull #a
| MUT -> B.null #a
| CONST -> CB.null a
let g_is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot bool =
match t with
| IMMUT -> IB.g_is_null (b <: ibuffer a)
| MUT -> B.g_is_null (b <: buffer a)
| CONST -> B.g_is_null (CB.as_mbuf (b <: cbuffer a))
let live (#t:buftype) (#a:Type0) (h:HS.mem) (b:buffer_t t a) : Type =
match t with
| MUT -> B.live h (b <: buffer a)
| IMMUT -> IB.live h (b <: ibuffer a)
| CONST -> CB.live h (b <: cbuffer a)
let freeable (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot Type0 =
match t with
| IMMUT -> IB.freeable (b <: ibuffer a)
| MUT -> B.freeable (b <: buffer a)
| CONST -> B.freeable (CB.as_mbuf (b <: cbuffer a))
let loc (#t:buftype) (#a:Type0) (b:buffer_t t a) : GTot B.loc =
match t with
| MUT -> B.loc_buffer (b <: buffer a)
| IMMUT -> B.loc_buffer (b <: ibuffer a)
| CONST -> CB.loc_buffer (b <: cbuffer a)
let loc_addr_of_buffer (#t : buftype) (#a : Type0) (b : buffer_t t a) : GTot B.loc =
match t with
| IMMUT -> IB.loc_addr_of_buffer (b <: ibuffer a)
| MUT -> B.loc_addr_of_buffer (b <: buffer a)
| CONST -> B.loc_addr_of_buffer (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction noextract
let is_null (#t : buftype) (#a : Type0) (b : buffer_t t a) :
Stack bool
(requires (fun h -> live h b))
(ensures (fun h y h' -> h == h' /\ y == g_is_null b)) =
match t with
| IMMUT -> IB.is_null (b <: ibuffer a)
| MUT -> B.is_null (b <: buffer a)
| CONST -> CB.is_null (b <: cbuffer a)
let get (#t : buftype) (#a : Type0) (h : mem) (b : buffer_t t a) (i : nat{i < length b}) :
GTot a =
match t with
| IMMUT -> IB.get h (b <: ibuffer a) i
| MUT -> B.get h (b <: buffer a) i
| CONST -> B.get h (CB.as_mbuf (b <: cbuffer a)) i
#set-options "--max_ifuel 0"
let union (l1:B.loc) (l2:B.loc) : GTot B.loc = B.loc_union l1 l2
let ( |+| ) (l1:B.loc) (l2:B.loc) : GTot B.loc = union l1 l2
(** Generalized modification clause for Buffer locations *)
let modifies (s:B.loc) (h1 h2:HS.mem) = B.modifies s h1 h2
(* JP: redefining is generally dangerous; someone may inadvertently write a pattern
for the disjoint predicate below, which does not enjoy transitivity, etc. and run
into strange behavior. This explains why the SMTPat on mut_immut_disjoint
operates over B.loc_disjoint, not disjoint. *)
(** Disjointness clause for Buffers *)
let disjoint (#t1 #t2:buftype) (#a1 #a2:Type0) (b1:buffer_t t1 a1) (b2:buffer_t t2 a2) =
B.loc_disjoint (loc b1) (loc b2)
let mut_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t IMMUT t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h ib))
(ensures (disjoint b ib))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h ib)]
=
IB.buffer_immutable_buffer_disjoint b ib h
let mut_const_immut_disjoint #t #t' (b: buffer_t MUT t) (ib: buffer_t CONST t') (h: HS.mem):
Lemma
(requires (B.live h b /\ B.live h (CB.as_mbuf ib) /\ CB.qual_of #t' ib == CB.IMMUTABLE))
(ensures (B.loc_disjoint (loc b) (loc ib)))
[SMTPat (B.loc_disjoint (loc b) (loc ib)); SMTPat (B.live h b); SMTPat (B.live h (CB.as_mbuf ib))]
=
IB.buffer_immutable_buffer_disjoint #t #t' b (CB.as_mbuf #t' ib) h
(** Modifies nothing *)
let modifies0 (h1 h2:HS.mem) =
modifies (B.loc_none) h1 h2
(** Modifies one buffer *)
let modifies1 (#a:Type0) (b:buffer_t MUT a) (h1 h2:HS.mem) =
modifies (loc b) h1 h2
(** Modifies two buffers *)
let modifies2 (#a0:Type0) (#a1:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1) h1 h2
(** Modifies three buffers *)
let modifies3 (#a0:Type0) (#a1:Type0) (#a2:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2) h1 h2
(** Modifies four buffers *)
let modifies4 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3) h1 h2
(** Modifies five buffers *)
let modifies5 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4) h1 h2
(** Modifies six buffers *)
let modifies6 (#a0:Type0) (#a1:Type0) (#a2:Type0) (#a3:Type0) (#a4:Type0) (#a5:Type0)
(b0:buffer_t MUT a0) (b1:buffer_t MUT a1) (b2:buffer_t MUT a2) (b3:buffer_t MUT a3)
(b4:buffer_t MUT a4) (b5:buffer_t MUT a5) (h1 h2: HS.mem) =
modifies (loc b0 |+| loc b1 |+| loc b2 |+| loc b3 |+| loc b4 |+| loc b5) h1 h2
(** Ghost reveal a buffer as a sequence *)
let as_seq (#t:buftype) (#a:Type0) (#len:size_t) (h:HS.mem) (b:lbuffer_t t a len) :
GTot (Seq.lseq a (v len)) =
match t with
| MUT -> B.as_seq h (b <: buffer a)
| IMMUT -> IB.as_seq h (b <: ibuffer a)
| CONST -> CB.as_seq h (b <: cbuffer a)
(** Ghostly get a sub-buffer of a buffer *)
let gsub (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len)
(start:size_t) (n:size_t{v start + v n <= v len}) : GTot (lbuffer_t t a n)
=
match t with
| IMMUT->
let b = IB.igsub (b <: ibuffer a) start n in
assert (B.length b == v n);
(b <: ilbuffer a n)
| MUT ->
let b = B.gsub (b <: buffer a) start n in
assert (B.length b == v n);
(b <: lbuffer a n)
| CONST ->
let b = CB.gsub (b <: cbuffer a) start n in
assert (CB.length b == v n);
(b <: clbuffer a n)
(** JP: are these not covered already by standard SMT patterns? is this to avoid
having to invert on `buftype`? *)
val live_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h:mem
-> Lemma
(ensures live h b ==> live h (gsub b start n))
[SMTPat (live h (gsub b start n))]
val modifies_sub: #t:buftype -> #a:Type0 -> #len:size_t -> b:lbuffer_t t a len
-> start:size_t -> n:size_t{v start + v n <= v len} -> h0:mem -> h1:mem
-> Lemma
(requires modifies (loc (gsub b start n)) h0 h1)
(ensures modifies (loc b) h0 h1)
[SMTPat (modifies (loc (gsub b start n)) h0 h1)]
inline_for_extraction
val as_seq_gsub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:HS.mem
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Lemma
(as_seq h (gsub b start n) ==
Seq.sub #a #(v len) (as_seq h b) (v start) (v n))
[SMTPat (Seq.sub #a #(v len) (as_seq h b) (v start) (v n))]
(** Statefully get a sub-buffer of a buffer *)
inline_for_extraction
val sub:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len
-> start:size_t
-> n:size_t{v start + v n <= v len} ->
Stack (lbuffer_t t a n)
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 -> h0 == h1 /\ live h1 r /\ r == gsub b start n)
(** Statefully read an element in a buffer *)
inline_for_extraction
val index:
#t:buftype
-> #a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer_t t a len
-> i:size_t{v i < v len} ->
Stack a
(requires fun h0 -> live h0 b)
(ensures fun h0 r h1 ->
h0 == h1 /\
r == Seq.index #a #(v len) (as_seq h1 b) (v i))
(** Update a specific value in a mutable buffer *)
inline_for_extraction
val upd:
#a:Type0
-> #len:size_t{v len > 0}
-> b:lbuffer a len
-> i:size_t{v i < v len}
-> x:a ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 b == Seq.upd #a #(v len) (as_seq h0 b) (v i) x)
(** Operator for updating a mutable buffer: b.(i) <- x *)
inline_for_extraction
let op_Array_Assignment #a #len = upd #a #len
(** Operator for accessing a buffer: b.(i) *)
inline_for_extraction
let op_Array_Access #t #a #len = index #t #a #len
(* 2018.16.11 SZ: this doesn't parse: let f a len (b:lbuffer a len) h = h.[| b |] *)
(** Operator for getting a ghost view of a buffer as a sequence: h.[(b)] *)
inline_for_extraction
let op_Brack_Lens_Access #t #a #len = as_seq #t #a #len
(** Ghostly read an element in a buffer *)
let bget (#t:buftype) (#a:Type0) (#len:size_t) (h:mem) (b:lbuffer_t t a len)
(i:size_nat{i < v len}) : GTot a
=
match t with
| MUT -> B.get h (b <: buffer a) i
| IMMUT -> IB.get h (b <: ibuffer a) i
| CONST -> FStar.Seq.index (CB.as_seq h (b <: cbuffer a)) i
(* We don't have access to Lib.Sequence to know `Lib.Sequence.index == FStar.Seq.index` *)
val bget_as_seq:
#t:buftype
-> #a:Type0
-> #len:size_t
-> h:mem
-> b:lbuffer_t t a len
-> i:size_nat
-> Lemma
(requires i < v len)
(ensures bget #t #a #len h b i == Seq.index #a #(v len) (as_seq h b) i)
[SMTPat (bget #t #a #len h b i)]
// An improved version of the predicate found in LowStar.Buffer, that uses
// loc_in (which has an equational reasoning theory via SMTPats rather than the
// cumbersome unused_in). Any questions should be addressed to Tahina.
unfold
let alloc_post_mem_common (#a:Type0) (#rrel #rel:LMB.srel a)
(b:LMB.mbuffer a rrel rel) (h0 h1:HS.mem) (s:Seq.seq a)
= LMB.live h1 b /\
B.loc_not_in (B.loc_addr_of_buffer b) h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
(HS.get_tip h1) == (HS.get_tip h0) /\
modifies LMB.loc_none h0 h1 /\
LMB.as_seq h1 b == s
let stack_allocated (#a:Type0) (#len:size_t) (b:lbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: B.buffer a = b in
alloc_post_mem_common b h0 h1 s /\
B.frameOf b = HS.get_tip h0 /\
B.frameOf b <> HyperStack.root
let global_allocated (#a:Type0) (#len:size_t) (b:glbuffer a len)
(h0:mem) (h1:mem) (s:Seq.lseq a (v len)) =
let b: ibuffer a = CB.as_mbuf b in
B.frameOf b == HyperStack.root /\
alloc_post_mem_common b h0 h1 s
let recallable (#t:buftype) (#a:Type0) (#len:size_t) (b:lbuffer_t t a len) =
match t with
| IMMUT -> B.recallable (b <: ibuffer a)
| MUT -> B.recallable (b <: buffer a)
| CONST -> B.recallable (CB.as_mbuf (b <: cbuffer a))
inline_for_extraction
val recall:
#t:buftype
-> #a:Type0
-> #len:size_t
-> b:lbuffer_t t a len ->
Stack unit
(requires fun _ -> recallable b)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b)
unfold private
let cpred (#a:Type0) (s:Seq.seq a) : B.spred a = fun s1 -> FStar.Seq.equal s s1
let witnessed (#a:Type0) (#len:size_t) (b:glbuffer a len) (s:Seq.lseq a (v len)) =
B.witnessed (CB.as_mbuf b) (cpred s)
(** Allocate a stack fixed-length mutable buffer and initialize it to value [init] *)
inline_for_extraction
val create:
#a:Type0
-> len:size_t
-> init:a ->
StackInline (lbuffer a len)
(requires fun h0 -> v len > 0)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create (v len) init))
#set-options "--max_fuel 1"
(** Allocate a stack fixed-length mutable buffer initialized to a list *)
inline_for_extraction
val createL:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
StackInline (lbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.alloca_of_list_pre #a init)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.of_list init))
(** Allocate a global fixed-length const immutable buffer initialized to value [init] *)
inline_for_extraction
val createL_global:
#a:Type0
-> init:list a{normalize (List.Tot.length init <= max_size_t)} ->
ST (glbuffer a (size (normalize_term (List.Tot.length init))))
(requires fun h0 -> B.gcmalloc_of_list_pre #a HyperStack.root init)
(ensures fun h0 b h1 -> global_allocated b h0 h1 (Seq.of_list init) /\
recallable b /\
witnessed b (Seq.of_list init))
(** Allocate a global fixed-length mutable buffer initialized to value [init] *)
inline_for_extraction
val createL_mglobal: #a:Type0 -> init:list a ->
ST (buffer a)
(requires fun h0 -> normalize (FStar.List.Tot.length init <= max_size_t))
(ensures fun h0 b h1 ->
B.frameOf b == HyperStack.root /\ B.recallable b /\
alloc_post_mem_common (b <: buffer a) h0 h1 (FStar.Seq.seq_of_list init) /\
length b == normalize_term (FStar.List.Tot.length init))
#set-options "--max_fuel 0"
(** Recall the liveness and contents of a global immutable buffer *)
inline_for_extraction
val recall_contents:
#a:Type0
-> #len:size_t{v len <= max_size_t}
-> b:glbuffer a len
-> s:Seq.lseq a (v len) ->
ST unit
(requires fun h0 -> (live h0 b \/ recallable b) /\ witnessed b s)
(ensures fun h0 _ h1 -> h0 == h1 /\ live h0 b /\ as_seq h0 b == s)
(** Copy a buffer into a mutable buffer *)
inline_for_extraction
val copy:
#t:buftype
-> #a:Type
-> #len:size_t
-> o:lbuffer a len
-> i:lbuffer_t t a len ->
Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint i o)
(ensures fun h0 _ h1 ->
modifies1 o h0 h1 /\
as_seq h1 o == as_seq h0 i)
(**
* Set all elements of a mutable buffer to a specific value
*
* WARNING: don't rely on the extracted implementation for secure erasure,
* C compilers may remove optimize it away.
*)
inline_for_extraction
val memset:
#a:Type
-> #blen:size_t
-> b:lbuffer a blen
-> w:a
-> len:size_t{v len <= v blen} ->
Stack unit
(requires fun h0 -> live h0 b)
(ensures fun h0 _ h1 ->
modifies1 b h0 h1 /\
as_seq h1 (gsub b 0ul len) == Seq.create (v len) w /\
as_seq h1 (gsub b len (blen -! len)) ==
as_seq h0 (gsub b len (blen -! len)))
(** Copy a buffer into a sub-buffer of a mutable buffer *)
inline_for_extraction
val update_sub:
#t:buftype
-> #a:Type
-> #len:size_t
-> dst:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> src:lbuffer_t t a n ->
Stack unit
(requires fun h -> live h dst /\ live h src /\ disjoint dst src)
(ensures fun h0 _ h1 ->
modifies1 dst h0 h1 /\
as_seq h1 dst == Seq.update_sub (as_seq h0 dst) (v start) (v n) (as_seq h0 src))
(** Update a mutable buffer in-place by applying a function on a sub-buffer of it *)
inline_for_extraction
val update_sub_f:
#a:Type
-> #len:size_t
-> h0:mem
-> buf:lbuffer a len
-> start:size_t
-> n:size_t{v start + v n <= v len}
-> spec:(mem -> GTot (Seq.lseq a (v n)))
-> f:(unit -> Stack unit
(requires fun h -> h0 == h)
(ensures fun h0 _ h1 ->
(let b = gsub buf start n in
modifies (loc b) h0 h1 /\
as_seq h1 b == spec h0))) ->
Stack unit
(requires fun h -> h0 == h /\ live h buf)
(ensures fun h0 _ h1 ->
modifies (loc buf) h0 h1 /\
as_seq h1 buf == Seq.update_sub #a #(v len) (as_seq h0 buf) (v start) (v n) (spec h0))
(** Copy two buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat2:
#t0:buftype
-> #t1:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> s:lbuffer a (len0 +! len1)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s /\
disjoint s s0 /\ disjoint s s1)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (as_seq h0 s0) (as_seq h0 s1))
(** Copy three buffers one after the other into a mutable buffer *)
inline_for_extraction
val concat3:
#t0:buftype
-> #t1:buftype
-> #t2:buftype
-> #a:Type0
-> len0:size_t
-> s0:lbuffer_t t0 a len0
-> len1:size_t{v len0 + v len1 <= max_size_t}
-> s1:lbuffer_t t1 a len1
-> len2:size_t{v len0 + v len1 + v len2 <= max_size_t}
-> s2:lbuffer_t t2 a len2
-> s:lbuffer a (len0 +! len1 +! len2)
-> Stack unit
(requires fun h ->
live h s0 /\ live h s1 /\ live h s2 /\ live h s /\
disjoint s s0 /\ disjoint s s1 /\ disjoint s s2)
(ensures fun h0 _ h1 ->
modifies1 s h0 h1 /\
as_seq h1 s == Seq.concat (Seq.concat (as_seq h0 s0) (as_seq h0 s1)) (as_seq h0 s2))
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> n:size_t
-> buf:lbuffer a len
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec2:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #len1:size_t
-> #len2:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies2 buf1 buf2 h0 h)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2)
(ensures fun _ _ h1 -> modifies2 buf1 buf2 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_nospec3:
#h0:mem
-> #a1:Type0
-> #a2:Type0
-> #a3:Type0
-> #len1:size_t
-> #len2:size_t
-> #len3:size_t
-> n:size_t
-> buf1:lbuffer a1 len1
-> buf2:lbuffer a2 len2
-> buf3:lbuffer a3 len3
-> impl: (i:size_t{v i < v n} -> Stack unit
(requires fun h -> modifies3 buf1 buf2 buf3 h0 h)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf1 /\ live h0 buf2 /\ live h0 buf3)
(ensures fun _ _ h1 -> modifies3 buf1 buf2 buf3 h0 h1)
(** Loop combinator with just memory safety specification *)
inline_for_extraction
val loop_range_nospec:
#h0:mem
-> #a:Type0
-> #len:size_t
-> start:size_t
-> n:size_t{v start + v n <= max_size_t}
-> buf:lbuffer a len
-> impl: (i:size_t{v start <= v i /\ v i < v start + v n} -> Stack unit
(requires fun h -> modifies1 buf h0 h)
(ensures fun _ _ h1 -> modifies1 buf h0 h1)) ->
Stack unit
(requires fun h -> h0 == h /\ live h0 buf)
(ensures fun _ _ h1 -> modifies1 buf h0 h1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.ConstBuffer.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Lib.Buffer.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "ByteSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LMB"
},
{
"abbrev": true,
"full_module": "LowStar.ConstBuffer",
"short_module": "CB"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
n: Lib.IntTypes.size_t ->
a_spec: (i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} -> Type) ->
refl:
(_: FStar.Monotonic.HyperStack.mem -> i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n}
-> Prims.GTot (a_spec i)) ->
footprint:
(i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} -> Prims.GTot LowStar.Monotonic.Buffer.loc) ->
spec:
(_: FStar.Monotonic.HyperStack.mem
-> Prims.GTot
(i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n} -> _: a_spec i -> a_spec (i + 1))) ->
i: Lib.IntTypes.size_nat{i <= Lib.IntTypes.v n} ->
h: FStar.Monotonic.HyperStack.mem
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Lib.IntTypes.size_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"LowStar.Monotonic.Buffer.loc",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.l_and",
"Lib.Buffer.modifies",
"Prims.eq2",
"Lib.LoopCombinators.repeat_gen"
] | [] | false | false | false | false | true | let loop_inv
(h0: mem)
(n: size_t)
(a_spec: (i: size_nat{i <= v n} -> Type))
(refl: (mem -> i: size_nat{i <= v n} -> GTot (a_spec i)))
(footprint: (i: size_nat{i <= v n} -> GTot B.loc))
(spec: (mem -> GTot (i: size_nat{i < v n} -> a_spec i -> a_spec (i + 1))))
(i: size_nat{i <= v n})
(h: mem)
: Type0 =
| modifies (footprint i) h0 h /\ refl h i == Loop.repeat_gen i a_spec (spec h0) (refl h0 0) | false |
LowParse.Slice.fst | LowParse.Slice.bytes_of_slice_from | val bytes_of_slice_from (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes | val bytes_of_slice_from (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes | let bytes_of_slice_from (#rrel #rel: _)
(h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes =
if (U32.v pos <= U32.v s.len)
then Seq.slice (B.as_seq h s.base) (U32.v pos) (U32.v s.len)
else Seq.empty | {
"file_name": "src/lowparse/LowParse.Slice.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 52,
"start_col": 0,
"start_line": 48
} | module LowParse.Slice
open LowParse.Bytes
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
inline_for_extraction
noextract
type srel (a: Type) = (B.srel a)
inline_for_extraction
noextract
let buffer_srel_of_srel (#a: Type) (s: srel a) : Tot (B.srel a) =
s
inline_for_extraction
noextract
let srel_of_buffer_srel (#a: Type) (s: B.srel a) : Tot (srel a) =
s
let buffer_srel_of_srel_of_buffer_srel (#a: Type) (s: B.srel a) : Lemma
(buffer_srel_of_srel (srel_of_buffer_srel s) == s)
[SMTPat (buffer_srel_of_srel (srel_of_buffer_srel s))]
= ()
noeq
inline_for_extraction
type slice (rrel rel: srel byte) = {
base: B.mbuffer byte (buffer_srel_of_srel rrel) (buffer_srel_of_srel rel);
len: (len: U32.t { U32.v len <= B.length base } );
}
inline_for_extraction
noextract
let make_slice
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t { U32.v len <= B.length b } )
: Tot (slice (srel_of_buffer_srel rrel) (srel_of_buffer_srel rel))
= {
base = b;
len = len;
}
let live_slice (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) : GTot Type0 = B.live h s.base | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Bytes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Slice.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> Prims.GTot LowParse.Bytes.bytes | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.bool",
"FStar.Seq.Base.empty",
"LowParse.Bytes.bytes"
] | [] | false | false | false | false | false | let bytes_of_slice_from (#rrel #rel: _) (h: HS.mem) (s: slice rrel rel) (pos: U32.t) : GTot bytes =
| if (U32.v pos <= U32.v s.len)
then Seq.slice (B.as_seq h s.base) (U32.v pos) (U32.v s.len)
else Seq.empty | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.